AI Hints
Home›Data Science Tutorial›Better Charts and Your Career
Data Science · Lesson 78 of 101

Small Multiples

Twelve lines, no spaghetti.

⏱ 2 min read▶ Video at 2:13:00🎓 Free
Watch this lesson in the Data Science courseWatch on YouTube ↗Full Data Science course

Twelve cafes on one line chart looks like a plate of spaghetti. Nobody can follow any line. The famous designer Edward Tufte had a beautifully simple answer. Don't put everything on one chart. Make twelve small charts.

Small Multiples
From the video: Small Multiples
  • Twelve lines look like spaghetti
  • Nobody can follow one
  • Make twelve small charts

One small chart per cafe

We make a three by four grid of charts, all on the same scale. In each one, we first draw all of the cafes in light grey, as background. Then we draw that panel's cafe in a strong colour. Run it. Each cafe can now be seen clearly, against the rest. Your eye can jump between panels. Because all of the axes match, you can compare them directly. This one trick upgrades nearly every crowded chart.

small_multiples.pypython
import pandas as pd
import matplotlib.pyplot as plt

sales = pd.read_csv("sales.csv", parse_dates=["date"])
m = sales.groupby(["city", pd.Grouper(key="date", freq="ME")])["revenue"].sum().unstack(0) / 1000

fig, axes = plt.subplots(3, 4, figsize=(11, 5), sharex=True, sharey=True)
for ax, city in zip(axes.flat, m.columns):
    ax.plot(m.index, m.values, color="lightgray", lw=.7)
    ax.plot(m.index, m[city], color="tab:orange", lw=2)
    ax.set_title(city, fontsize=10); ax.tick_params(labelbottom=False)
plt.tight_layout(); plt.savefig("small.png", dpi=100)
print("Peak city:", m.max().idxmax())
Output
Peak city: Osaka

Summary

Same scale, grey for context, and one colour for focus. Next, a chart that shows patterns across two dimensions at once.

Key takeaways
  • Split crowded charts
  • Keep the same scale
  • Grey background, one highlight
Next up: Heatmaps — two dimensions at a glance