Pie Charts & Subplots in Matplotlib — Baby Steps
Keyword: matplotlib pie chart • Difficulty: Beginner • Author: Champak Roy
Pie charts display how data categories relate to a whole. Subplots help you compare multiple pies side by side. This example runs directly in your browser using Pyodide — a full Python environment in WebAssembly.
Examples
labels = ['A','B','C']; sizes = [30,45,25]
plt.pie(sizes, labels=labels, autopct='%1.1f%%'); plt.axis('equal')
fig, axes = plt.subplots(1,2,figsize=(8,4))
axes[0].pie(sizes,...)
axes[1].pie(other_sizes,...)
plt.tight_layout()
🧪 Practice: Run Matplotlib with Pyodide
Click Preload Pyodide to prepare the environment. Then edit the Python code and click Run & Render to see the chart below.
Idle
Console / stderr:
No chart yet — run code to render a PNG here.
Tips
- Always return base64 as the last expression, not printed text.
- Call
plt.close(fig)after saving to release memory. - If you see a traceback, read it in the console — it’s the Python error.
- Click “Open Image” to inspect any returned image separately.
0 Comments