legend=True.
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],
})
df.set_index("city")[["units"]].plot(kind="bar", legend=True)
plt.show()df = pd.DataFrame({
"city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
"units": [21, 15, 15, 18, 12],
"shillings": [2100, 1500, 1480, 1750, 1190],
})
df.set_index("city")[["units"]].plot(kind="bar", legend=False)
plt.show()df = pd.DataFrame({"mango": [12, 7], "soda": [9, 8]}, index=["Nairobi", "Mombasa"])
ax = df.plot(kind="bar")
ax.legend(title="product")
plt.show()print("legend=True when two series.")Pitfall
Always plt.show().