Compare without the clutter.
Compare category totals and choose a truthful baseline.
01 The idea
A bar chart encodes magnitude through length, so its baseline matters. Categories can be sorted by a meaningful order or by value, depending on the question. Use horizontal bars when names are long. Keep labels explicit, start the value axis at zero for ordinary magnitude comparisons, and avoid decorating the chart with unnecessary three-dimensional effects.
02 The experiment
Read it once. Predict what will happen. Then copy it into a .py file and run it in your local Python setup.
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
names = ["Build", "Test", "Review"]
minutes = [40, 25, 15]
fig, ax = plt.subplots(figsize=(6, 3.5), layout="constrained")
bars = ax.barh(names, minutes, color=["#ed5027", "#a0b888", "#6c805a"])
ax.bar_label(bars, padding=3)
ax.set(xlabel="Minutes", title="Where the work goes", xlim=(0, 48))
ax.invert_yaxis()
fig.savefig("matplotlib-bars.png", dpi=140, bbox_inches="tight")
plt.close(fig)
print("Saved matplotlib-bars.png")Saved matplotlib-bars.png

03 Under the hood
- 1
barh places category labels on the vertical axis and values along the horizontal axis.
- 2
bar_label adds values to the bars. Leave enough axis space so labels do not collide with the frame.
- 3
A zero baseline preserves the length comparison. If you intentionally use a different visual design, disclose the scale clearly rather than letting viewers assume ordinary bar semantics.
04 Your turn, builder
Create a vertical bar chart for three project budgets and label the currency on the value axis.
Reveal one possible solution +
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 3.5), layout="constrained")
bars = ax.bar(["Orbit", "Atlas", "Nova"], [120, 90, 150], color="#ed5027")
ax.bar_label(bars)
ax.set(ylabel="Budget (USD)", title="Practice budgets", ylim=(0, 175))
fig.savefig("challenge.png", dpi=140, bbox_inches="tight")
plt.close(fig)
print("Saved challenge.png")05 Check your signal
Why normally start a bar value axis at zero?
Experiment. Logged.
When you can explain the idea and make the example your own, mark it complete. Your log stays in this browser.
Keep exploring
Go deeper with the official Python guide ↗.