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 資源

透過相關的互動式教學、備忘單和程式碼比較來擴展您的知識。