Magnitude

Honest axis.

Honest axis.

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.ylim(0, 25)
plt.title("Honest axis from zero")
plt.show()
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.ylim(10, 22)
plt.title("Truncated — Nairobi looks twice Kisumu. It is not.")
plt.show()
df = pd.DataFrame({
    "city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
    "units": [21, 15, 15, 18, 12],
    "shillings": [2100, 1500, 1480, 1750, 1190],
})
plt.barh(df["city"], df["units"])
plt.xlim(0, 25)
plt.title("Horizontal, still from zero")
plt.show()
print("Start bars at zero unless you have a strong reason and label the break.")
Pitfall

Always plt.show(). Paste the whole editor.