Four panels.
Goal
Run every block and look at the Plot panel.
fig, axes = plt.subplots(2, 2, figsize=(8, 6))
axes[0, 0].bar(["Nairobi", "Mombasa", "Kisumu"], [21, 15, 15])
axes[0, 0].set_title("Units")
axes[0, 1].plot(["Jan", "Feb", "Mar", "Apr"], [48, 55, 92, 150], marker="o")
axes[0, 1].set_title("Nairobi rain")
axes[1, 0].scatter([12, 7, 9, 4], [1260, 1540, 945, 880])
axes[1, 0].set_title("Units vs shillings")
axes[1, 1].axis("off")
axes[1, 1].text(0.1, 0.5, "Nairobi leads units.\nRain peaks in April.")
fig.tight_layout()
plt.show()fig, ax = plt.subplots()
ax.bar(["Nairobi", "Mombasa"], [21, 15])
ax.set_title("Keep a dashboard to a few panels")
plt.show()print("Dashboard: one story, not every chart you know.")df = pd.DataFrame({
"city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
"units": [21, 15, 15, 18, 12],
"shillings": [2100, 1500, 1480, 1750, 1190],
})
print(df.sort_values("units", ascending=False).head(3).to_string(index=False))Pitfall
Always plt.show(). Paste the whole editor.