Misleading charts

Truncated bars.

Truncated bars.

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(10, 22)
plt.title("Lie: truncated bars")
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(0, 25)
plt.title("Redraw: from zero")
plt.show()
months = ["Jan", "Feb", "Mar", "Apr"]
fig, ax1 = plt.subplots()
ax1.plot(months, [48, 55, 92, 150], color="C0")
ax1.set_ylabel("mm", color="C0")
ax2 = ax1.twinx()
ax2.plot(months, [21, 19, 18, 22], color="C1")
ax2.set_ylabel("units", color="C1")
plt.title("Dual axis invites fake correlation")
plt.show()
print("One question, one scale. Dual axes are a last resort.")
Pitfall

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