matplotlib

Data

图表渲染

概述 matplotlib

Matplotlib是 Python 最广泛使用的绘图库。它使您只需几行代码即可创建出版质量的 2D 图表 - 条形图、折线图、散点图、直方图、饼图等等。Matplotlib与NumPy和Pandas紧密集成,使其成为几乎所有数据科学工作流程的默认可视化层。

PyRun直接在浏览器的专用 GRAPHS 选项卡内呈现Matplotlib图表。当您的代码调用 plt.show() 时,PyRun会截取该图形并将其显示为清晰的 SVG 与终端输出一起显示。不需要 Jupyter 笔记本或本地显示服务器 - 只需编写绘图代码并运行它即可。

代码和执行输出

在 GRAPHS 选项卡中呈现图表。

Matplotlib Bar Chart在编辑器中运行
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()

相关套餐

推荐的 Python 资源

通过相关的交互式教程、备忘单和代码比较来扩展您的知识。