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.
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...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.
More Examples
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.