Matplotlib長條圖
在 GRAPHS 標籤中呈現圖表。
概述
This script utilizes matplotlib to render a 2D aesthetic bar chart comparing language popularity.
It dynamically formats edge spines, figure sizes, and hex colors.
程式碼和執行輸出
This demonstrates matplotlib rendering over the browser engine inline.
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...逐步實施
- 數據視覺化
- Scientific analysis
- Stats reporting
常見問題解答
圖表出現在哪裡?
PyRun自動攔截 matplotlib 渲染端點並將它們透過管道傳輸到專用的隔離圖 DOM 元素中。