title, xlabel, ylabel.
Goal
Run every block.
df = pd.DataFrame({
"city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
"units": [21, 15, 15, 18, 12],
"shillings": [2100, 1500, 1480, 1750, 1190],
})
ax = df.plot(x="city", y="units", kind="bar", title="Kiosk units")
ax.set_xlabel("city")
ax.set_ylabel("units")
plt.show()df = pd.DataFrame({
"city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
"units": [21, 15, 15, 18, 12],
"shillings": [2100, 1500, 1480, 1750, 1190],
})
df.plot(x="city", y="shillings", kind="barh", title="Shillings")
plt.show()df = pd.DataFrame({
"month": ["Jan", "Feb", "Mar", "Apr"] * 2,
"mm": [48, 55, 92, 150, 22, 18, 40, 80],
"city": ["Nairobi"] * 4 + ["Mombasa"] * 4,
})
df[df.city=="Nairobi"].plot(x="month", y="mm", title="Nairobi mm", marker="o")
plt.show()print("title= on plot() or ax.set_title.")Pitfall
Always plt.show().