Matplotlib条形图
在 GRAPHS 选项卡中呈现图表。
概述
该脚本利用 matplotlib 渲染比较语言流行度的 2D 美观条形图。
它动态地设置边缘脊柱、图形大小和十六进制颜色的格式。
代码和执行输出
这演示了 matplotlib 在浏览器引擎上的内联渲染。
chart.py
在编辑器中尝试import matplotlib.pyplot as plt
import numpy as np
langs = ['Python', 'JavaScript', 'TypeScript', 'Rust', 'Go']
scores = [95, 88, 82, 78, 75]
colors = ['#0D9488', '#F59E0B', '#3B82F6', '#EF4444', '#8B5CF6']
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(langs, scores, color=colors, edgecolor='none', width=0.6)
ax.set_title('Language Popularity Index 2025', fontsize=14, fontweight='bold', pad=15)
ax.set_ylabel('Score', fontsize=11)
ax.set_ylim(60, 100)
ax.spines[['top', 'right']].set_visible(False)
for bar, score in zip(bars, scores):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.5,
str(score), ha='center', va='bottom', fontweight='bold')
plt.tight_layout()
plt.show()端子输出
Rendered visualization in the Graphs tab...逐步实施
- 数据可视化
- 科学分析
- 统计报告
常见问题解答
图表出现在哪里?
PyRun自动拦截 matplotlib 渲染端点并将它们通过管道传输到专用的隔离图 DOM 元素中。