Meet the distribution.
Explore how numeric observations are spread rather than comparing categories.
01 The idea
A histogram groups numeric observations into intervals and counts the observations in each interval. Bin boundaries change the visible shape, so they are an analysis choice rather than a decorative setting. Inspect the sample size and units, try reasonable alternative bins, and avoid claiming that a tiny sample reveals a universal distribution.
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
durations = [8, 12, 13, 18, 22, 24, 25, 32, 35, 41, 44, 47]
fig, ax = plt.subplots(figsize=(6, 3.5), layout="constrained")
ax.hist(durations, bins=[0, 10, 20, 30, 40, 50], color="#ed5027", edgecolor="white")
ax.set(xlabel="Task duration (minutes)", ylabel="Number of tasks", title="How long do tasks take?")
ax.set_xticks([0, 10, 20, 30, 40, 50])
fig.savefig("matplotlib-histograms.png", dpi=140, bbox_inches="tight")
plt.close(fig)
print("Saved matplotlib-histograms.png")Saved matplotlib-histograms.png

03 Under the hood
- 1
The numeric bin boundaries make the intervals explicit. Most bins include the left edge and exclude the right; the final bin includes its right edge.
- 2
The y-axis counts observations here. density=True changes the interpretation to probability density, not directly to a percentage per bin.
- 3
Consider outliers and missing data before plotting. Show both the summary and what was excluded when an exclusion materially changes the story.
04 Your turn, builder
Create the same histogram with wider intervals and compare what information becomes less visible.
Reveal one possible solution +
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
values = [8, 12, 13, 18, 22, 24, 25, 32, 35, 41, 44, 47]
fig, ax = plt.subplots(figsize=(6, 3.5), layout="constrained")
ax.hist(values, bins=[0, 25, 50], edgecolor="white", color="#ed5027")
ax.set(xlabel="Minutes", ylabel="Task count", title="A coarser view")
fig.savefig("challenge.png", dpi=140, bbox_inches="tight")
plt.close(fig)
print("Saved challenge.png")05 Check your signal
What determines which interval contains a value?
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 ↗.