Choose a chart for the question

3.11.2

Choose how to display categories, trends, distributions, and relationships.

On this page

Compare categories and show changes over time

Use a bar chart to compare distinct categories. Start a magnitude bar chart at zero because bar length encodes size. Use a line chart when the horizontal axis has a meaningful sequence such as time. For irregularly spaced dates, plot date values so the spacing reflects elapsed time.

import matplotlib.pyplot as plt

fig, (by_store, by_month) = plt.subplots(1, 2, layout="constrained")
bars = by_store.bar(["A", "B", "C"], [8, 12, 6])
by_store.bar_label(bars)
by_store.set(ylim=(0, 14), xlabel="Store", ylabel="Orders")

by_month.plot(["Jan", "Feb", "Mar"], [20, 24, 22], marker="o")
by_month.set(xlabel="Month", ylabel="Orders")
plt.show()
Bars compare stores A, B, and C at 8, 12, and 6 orders. A line shows 20, 24, and 22 orders from January to March. Download image
Both examples measure orders. The horizontal axis determines what each chart compares.

Show a distribution or a relationship

A histogram groups one numeric measure into intervals. Change the bin width to check whether the visible pattern is stable. A scatter plot places each observation at its two numeric coordinates. Inspect overlap, unusual points, and possible subgroups before interpreting the pattern.

import matplotlib.pyplot as plt

fig, (histogram, scatter) = plt.subplots(1, 2, layout="constrained")
durations = [12, 16, 17, 22, 24, 28, 33, 35]
histogram.hist(durations, bins=[10, 20, 30, 40], edgecolor="white")
histogram.set(xlabel="Duration (min)", ylabel="Deliveries")

distance = [1, 2, 2.5, 3, 4, 5, 5.5, 6]
scatter.scatter(distance, durations)
scatter.set(xlabel="Distance (km)", ylabel="Duration (min)")
plt.show()
The histogram counts durations in three bins with 3, 3, and 2 deliveries. The scatter plot shows eight distances and their paired durations. Download image
The same delivery durations answer two different questions when plotted alone or paired with distance.

Official references