savefig.
Goal
Run every block and look at the Plot panel.
df = pd.DataFrame({
"city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
"units": [21, 15, 15, 18, 12],
"shillings": [2100, 1500, 1480, 1750, 1190],
})
plt.bar(df["city"], df["units"])
plt.title("Units")
plt.savefig("units.png", dpi=120, bbox_inches="tight")
plt.show()
print("wrote units.png")df = pd.DataFrame({
"month": ["Jan", "Feb", "Mar", "Apr"] * 2,
"mm": [48, 55, 92, 150, 22, 18, 40, 80],
"city": ["Nairobi"] * 4 + ["Mombasa"] * 4,
})
nairobi = df[df["city"] == "Nairobi"]
plt.plot(nairobi["month"], nairobi["mm"], marker="o")
plt.savefig("rain.png", dpi=120, bbox_inches="tight")
plt.show()
print("wrote rain.png")Pitfall
Always plt.show(). Paste the whole editor.