Matplotlib Bar Chart
Renders a chart in the GRAPHS tab.
How it Works
This script utilizes matplotlib to render a 2D aesthetic bar chart comparing language popularity.
It dynamically formats edge spines, figure sizes, and hex colors.
Source Code
This demonstrates matplotlib rendering over the browser engine inline.
chart.py
Try in Editorimport 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()Terminal Output
Rendered visualization in the Graphs tab...Real-world Applications
- Data visualization
- Scientific analysis
- Stats reporting
Frequently Asked Questions
Where does the graph appear?
PyRun automatically intercepts matplotlib rendering endpoints and pipes them into the dedicated isolated Graphs DOM element.