Skip to content
LumenaryAcademy
Foundations 75 min

Visualisation and storytelling

Choosing a chart for the question, what the eye judges well and badly, colour for everyone, honest axes and uncertainty, and writing the story the numbers support.

Code tested · 5AI-draftedAwaiting review by a data scientist

Your guides: Chloe · The Statistician, Margaret · The Simulator, Gideon · The Sceptic

MotivationH

A chart is an argument

A regional health service introduced online booking at six clinics in March and wants to know whether waiting times fell. The analysis is done: means for February and April, intervals for the change, notes on the data. Now it has to reach the board, whose members will look at one chart for perhaps half a minute before moving to the next agenda item. Whatever they take away in those thirty seconds is the result of the analysis, whatever the appendix says.

A chart is therefore not decoration on top of an analysis; it is an argument, and it can be a good argument or a misleading one. The same numbers can be drawn so that the main finding jumps out, so that it hides, or so that a small change looks dramatic. This lesson is about the choices that make the difference: which chart for which question, what the human visual system judges well and badly, colour that works for everyone, honest axes and uncertainty, and the words around the chart. It ends with a before-and-after redesign of the clinic chart.

The habits here build on the previous lessons: exploratory data analysis made charts for you; this lesson makes them for other people. For the statistics behind intervals and comparisons, see estimation and confidence intervals in Lumenary Statistics, and for a younger reader's tour of how charts mislead, misleading statistics.

IntuitionH

Start from the question

Most bad charts begin with the chart type ("let's do a pie chart") instead of the question. Start by writing down, in one sentence, what the reader should be able to see. Then pick the simplest chart that makes it visible.

The reader needs to…Good first choicesUsually avoid
compare amounts across categoriessorted bar chart (from zero), dot plotpie with many slices, 3D bars
see change over timeline chart; small multiples for several seriesbars for long daily series, dual y-axes
see a distributionhistogram, box plot, strip or violin plota bar of the mean alone
see a relationshipscatter plot, with a trend line if it helpstwo line charts side by side
see parts of a wholestacked bar; a pie only for two or three partspie with ten slices, donut with a hole of text
compare before and after per categorydumbbell (slope) chartgrouped bars with a legend
see uncertaintypoints with intervals, many-outcome displaysbare point estimates, or error bars nobody explains
see wherea map only if location matters; otherwise a sorted chartchoropleths where big empty areas dominate

Two rules of thumb sit behind the table. One chart, one message: if a chart must show three things, make three charts, or small multiples (the same small chart repeated per group, on shared axes). And sort categories by value unless they have a natural order (months, age groups, ratings), because a sorted chart answers "which is biggest?" before the reader asks.

ExplanationH

Perception: position beats area

In 1984 William Cleveland and Robert McGill asked people to judge proportions encoded in different ways, and measured their errors. Judgements of position along a common scale were the most accurate; then position on separate, non-aligned scales; then length; then angle and slope; then area; with volume, colour saturation and colour hue the least accurate for reading quantities. Later experiments, including large online replications, have broadly confirmed the ordering. It explains most of the standard advice: bar charts and dot plots use position and length, pies use angle and area, and bubble charts and colour scales use the weakest channels of all.

angle (pie)area (circles)length (bars)position (dots)BusRailBicycleWalkBusRailBicycleWalkBusRailBicycleWalk028%20%25%30%
The same four shares (Bus 21%, Rail 27%, Bicycle 24%, Walk 28%) encoded four ways. Ranking them from the pie or the circles is guesswork; from the bars and dots it is immediate. Dots on a common scale need not start at zero, because position, not length, carries the value; bars must start at zero.

Area is a particular trap, because there are two ways to scale a circle or icon and only one is honest. If a value doubles and you double the radius, the area quadruples, and readers (who respond to area) see a fourfold increase. Edward Tufte's lie factor measures distortions like this: the relative change shown in the graphic divided by the relative change in the data. An honest graphic has a lie factor of 1.

python
def lie_factor(data_a, data_b, shown_a, shown_b):
    """Tufte's lie factor: the relative change a graphic shows, over the relative change in the data."""
    return ((shown_b - shown_a) / shown_a) / ((data_b - data_a) / data_a)

# Bars for 50 and 55 drawn on an axis that starts at 48 instead of 0.
print("truncated bars:   ", round(lie_factor(50, 55, 50 - 48, 55 - 48), 1))
print("bars from zero:   ", round(lie_factor(50, 55, 50, 55), 1))

# Circles whose radius (not area) is proportional to the value: 10 and 20.
import math
area = lambda r: math.pi * r * r
print("radius-scaled:    ", round(lie_factor(10, 20, area(10), area(20)), 1))
print("area-scaled:      ", round(lie_factor(10, 20, area(math.sqrt(10)), area(math.sqrt(20))), 1))

# A pie and a dot plot of the same four shares: which one lets you rank them?
shares = {"Bus": 21, "Rail": 27, "Bicycle": 24, "Walk": 28}
for name, s in shares.items():
    print(f"{name:8} {s:3d}%  slice {3.6 * s:5.1f} degrees   dot at {'.' * (s - 15)}o")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
ExplanationH

Colour and accessibility

Colour does three different jobs, and each needs a different kind of palette.

  • Categorical (qualitative) palettes distinguish groups that have no order: towns, products, transport modes. Use few colours (five or six at most is a good limit); beyond that, label directly or split into small multiples.
  • Sequential palettes show ordered quantities from low to high, usually light to dark. Perceptually uniform colour maps such as viridis change in lightness evenly, so equal steps in the data look like equal steps on the page, and they survive printing in greyscale. The old "rainbow" colour map does neither: it creates bright bands that look like boundaries in the data.
  • Diverging palettes show quantities above and below a meaningful midpoint (zero change, a target, the national average), with two hues meeting at a neutral colour.

About one man in twelve and one woman in two hundred of Northern European ancestry have some form of red–green colour-vision deficiency, with lower rates in many other populations; across a large audience, someone always does. So: never let colour be the only way to tell things apart (add labels, shapes or position); avoid red against green as the main contrast; and check contrast against the background. The Web Content Accessibility Guidelines define a contrast ratio from 1:1 to 21:1 and ask for at least 4.5:1 for normal text and 3:1 for graphical elements that carry meaning. All of this can be computed.

python
import numpy as np

def to_linear(hex_colour):
    """sRGB hex such as '#1f77b4' to linear-light RGB in [0, 1] (the sRGB transfer function)."""
    c = np.array([int(hex_colour[i:i + 2], 16) for i in (1, 3, 5)]) / 255
    return np.where(c <= 0.04045, c / 12.92, ((c + 0.055) / 1.055) ** 2.4)

def luminance(rgb):
    return float(rgb @ [0.2126, 0.7152, 0.0722])

def contrast(a, b):
    """WCAG 2 contrast ratio between two colours, from 1:1 to 21:1."""
    hi, lo = sorted([luminance(to_linear(a)), luminance(to_linear(b))], reverse=True)
    return (hi + 0.05) / (lo + 0.05)

def lab(rgb):
    """Linear RGB to CIELAB (D65 white), to measure how different two colours look."""
    xyz = np.array([[0.4124, 0.3576, 0.1805], [0.2126, 0.7152, 0.0722],
                    [0.0193, 0.1192, 0.9505]]) @ rgb / [0.9505, 1.0, 1.089]
    f = np.where(xyz > (6 / 29) ** 3, np.cbrt(xyz), xyz / (3 * (6 / 29) ** 2) + 4 / 29)
    return np.array([116 * f[1] - 16, 500 * (f[0] - f[1]), 200 * (f[1] - f[2])])

# Machado, Oliveira and Fernandes (2009): simulated deuteranopia, in linear RGB.
DEUTAN = np.array([[0.367322, 0.860646, -0.227968],
                   [0.280085, 0.672501, 0.047413],
                   [-0.011820, 0.042940, 0.968881]])

def difference(a, b, deutan=False):
    ra, rb = to_linear(a), to_linear(b)
    if deutan:
        ra, rb = np.clip(DEUTAN @ ra, 0, 1), np.clip(DEUTAN @ rb, 0, 1)
    return float(np.linalg.norm(lab(ra) - lab(rb)))           # CIE76 colour difference

print("contrast with a white background (graphics need at least 3:1):")
for name, c in [("light grey", "#cccccc"), ("yellow", "#f2c500"), ("mid blue", "#1f77b4"),
                ("dark grey", "#595959"), ("orange", "#e66100")]:
    print(f"  {name:10} {c}  {contrast(c, '#ffffff'):4.1f}:1")

print("\ncolour difference (CIE76; under about 10 is hard to tell apart in a small mark):")
for a, b, label in [("#d62728", "#2ca02c", "red vs green"), ("#e66100", "#5d3a9b", "orange vs purple"),
                    ("#1f77b4", "#ff7f0e", "blue vs orange")]:
    print(f"  {label:17} normal vision {difference(a, b):5.1f}   simulated deuteranopia {difference(a, b, True):5.1f}")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Light grey and a bright yellow, both popular for "secondary" series, fail the 3:1 rule on white; the mid blue, the dark grey and the orange pass. The colour differences tell the bigger story: red and green that differ by about 120 units for typical vision differ by about 7 under simulated deuteranopia (the most common form of red–green deficiency), so a chart that relies on them becomes a puzzle for millions of readers. Orange against purple, or blue against orange, stay far apart. Tools such as ColorBrewer and the colour-blind simulators built into many design programs make these checks routine.

Accessibility goes beyond colour. Give every chart a text alternative that states its message (as the figures in this lesson do); make text large enough to read on a phone; and put labels next to the data instead of in a legend that the eye must keep returning to.

ExplanationH

Honest axes and uncertainty

A handful of rules prevent most misleading charts.

  • Bars and areas start at zero. Their length or area is the value, so a truncated axis multiplies differences (the lie factor of 25 above). Dot plots and line charts encode values by position and may zoom in, as long as the axis is clearly labelled.
  • Be wary of dual y-axes. Two series on two independent scales can be made to cross, diverge or move together at will by choosing the scales. Use two panels, or index both series to 100 at a common starting point.
  • Choose scales for the question. A log scale shows rates of growth (equal steps for equal percentage changes) and is the right choice for things like epidemic curves or prices over decades; say clearly that it is a log scale. Per-capita rates beat raw counts when populations differ.
  • Show the denominator and the time window. "Complaints doubled" means little without "from 4 to 8 out of 12,000 orders" and the period chosen; a carefully chosen start date can manufacture almost any trend.
  • Show uncertainty. A point estimate without an interval invites readers to over-interpret small differences. Show intervals, show the raw data when there are few points, and say in words what the interval means.

Here are the clinic data. The block computes each clinic's mean wait before and after, and a 95% bootstrap interval for the change (resampling each month's patients 2,000 times; see resampling and simulation), and prints a text version of the chart the board will see.

python
import numpy as np
import pandas as pd

# Synthetic waiting times (minutes) at six clinics, in February (before online booking) and April.
rng = np.random.default_rng(8)
clinics = ["Amani", "Bela Vista", "Sakura", "Al-Nur", "Lakeside", "Hill Road"]
before_mean = [38, 45, 52, 41, 35, 48]
after_mean = [27, 33, 50, 30, 31, 34]
rows = []
for c, b, a in zip(clinics, before_mean, after_mean):
    for month, mu in [("Feb", b), ("Apr", a)]:
        n = int(rng.integers(60, 250))
        rows += [(c, month, w) for w in rng.gamma(3.0, mu / 3.0, n).round(0)]
waits = pd.DataFrame(rows, columns=["clinic", "month", "minutes"])

def boot_ci(x, y, reps=2000):
    """95% bootstrap interval for mean(y) - mean(x): resample each month's patients."""
    diffs = [rng.choice(y, len(y)).mean() - rng.choice(x, len(x)).mean() for _ in range(reps)]
    return np.percentile(diffs, [2.5, 97.5])

out = []
for c, g in waits.groupby("clinic"):
    feb, apr = g.loc[g.month == "Feb", "minutes"].to_numpy(), g.loc[g.month == "Apr", "minutes"].to_numpy()
    lo, hi = boot_ci(feb, apr)
    out.append((c, len(feb), len(apr), feb.mean(), apr.mean(), apr.mean() - feb.mean(), lo, hi))
res = pd.DataFrame(out, columns=["clinic", "n_feb", "n_apr", "feb", "apr", "change", "lo", "hi"])
res = res.sort_values("change").reset_index(drop=True)
print(res.round(1).to_string(index=False))

# A text dumbbell chart: o = February, * = April, on a scale from 20 to 60 minutes.
print("\n" + " " * 12 + "20        30        40        50        60")
for r in res.itertuples():
    line = [" "] * 41
    a, b = sorted([round(r.feb) - 20, round(r.apr) - 20])
    for i in range(a, b + 1):
        line[i] = "-"
    line[round(r.feb) - 20], line[round(r.apr) - 20] = "o", "*"
    print(f"{r.clinic:>11} " + "".join(line) + f"  {r.change:+.0f} min ({r.lo:+.0f} to {r.hi:+.0f})")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Four clinics show falls whose intervals lie wholly below zero, from 8 to 19 minutes. At Lakeside and Sakura the intervals include zero: the data are consistent with no change, so the honest word is unclear. Notice also that Lakeside's interval is wide (from −10 to +2 minutes) because only 64 patients were recorded there in February; sample sizes belong somewhere a curious reader can find them.

Worked examplesH

A before-and-after redesign

Here is the chart that was first drafted for the board, from exactly the numbers above.

Clinic waiting timesFebApr25303540455055Al-NurAmaniBela VistaHill RoadLakesideSakura
Before: grouped bars in alphabetical order, a y-axis starting at 25 minutes, red and green as the only distinction between months, heavy gridlines, a legend far from the data, a title that states no finding, and no uncertainty.

Read it as a board member would, and list what goes wrong.

  1. The axis starts at 25. Bela Vista's April bar looks about a sixth the height of its February bar, a fall of more than 80%; the real fall is from 47.9 to 28.6 minutes, about 40%.
  2. Alphabetical order means the eye has to hunt for the biggest change.
  3. Red against green carries the only distinction between the months, so for readers with red–green deficiency the pairs are hard to tell apart; and the legend sits in a corner, far from the bars.
  4. The title says what the chart is, not what it shows.
  5. No uncertainty. Sakura's and Lakeside's small falls look as real as the others.
  6. Grouped bars make the reader compare bar heights within each pair and then compare those differences across pairs, a two-step comparison of lengths that a dumbbell chart turns into one look along a row.

And here is the redesign.

Waits fell at four of six clinics after online booking beganMean wait in minutes, February (open circle) and April (filled); right: change with 95% interval2030405060minutesBela Vista−19 (−27 to −12)Hill Road−16 (−22 to −10)Amani−11 (−15 to −7)Al-Nur−8 (−12 to −3)Lakeside−4 (−10 to +2): unclearSakura−2 (−7 to +4): unclear
After: a dumbbell chart, one row per clinic, sorted by the change. Open circles are February, filled circles April. Clinics whose interval excludes zero are in blue; the two with unclear changes are in grey. The title states the finding, the subtitle explains the encoding, and the change with its interval is printed beside each row.

What changed, and why each change matters:

  • Position on a common scale replaces bar length, so the axis can show 20 to 60 minutes honestly, and every clinic's before and after sit on one line that the eye follows.
  • Sorting by the change puts the answer to "where did waits fall most?" at the top.
  • Encoding by shape and lightness as well as hue (open versus filled circles) works in greyscale and for every kind of colour vision; colour is reserved for one meaning, clear versus unclear.
  • Direct labels replace the legend; the numbers with intervals sit beside each row for the reader who wants them.
  • The title is the finding, worded no more strongly than the evidence ("after", not "because of").
  • Everything else is removed: the gridlines are faint, there is no box, no shading, no decoration.

For your own notebooks, here is a matplotlib version of the redesign. It is shown for reference and is not run here, since the in-browser Python has no plotting library.

python
# Not run here: the redesigned chart in matplotlib, using the table `res` from the block above.
import matplotlib.pyplot as plt

res = res.sort_values("change", ascending=False)        # the biggest fall ends up at the top
fig, ax = plt.subplots(figsize=(7, 3.2))
for y, r in enumerate(res.itertuples()):
    colour = "tab:blue" if r.hi < 0 else "grey"
    ax.plot([r.apr, r.feb], [y, y], color=colour, lw=2.5)
    ax.scatter([r.feb], [y], s=40, facecolor="white", edgecolor=colour, zorder=3)
    ax.scatter([r.apr], [y], s=40, color=colour, zorder=3)
    ax.text(61, y, f"{r.change:+.0f} ({r.lo:+.0f} to {r.hi:+.0f})", va="center")
ax.set_yticks(range(len(res)), res["clinic"])
ax.set_xlim(20, 60)
ax.set_xlabel("mean wait (minutes)")
ax.set_title("Waits fell at four of six clinics after online booking began", loc="left")
for side in ["top", "right", "left"]:
    ax.spines[side].set_visible(False)
fig.tight_layout()
ExplanationH

Dashboards, reports and the story

Dashboards and reports do different jobs. A dashboard monitors known questions that recur: today's orders, this week's waiting times, whether a pipeline ran. It should be fast to read, stable from day to day, and honest about freshness ("data as of 06:00"). A report, memo or slide supports a particular decision: it has a question, an answer, the evidence and the caveats, in that order. Many organisations build dashboards when they need a decision, and end up with forty charts nobody reads. Tools for both are plentiful in 2026: open-source dashboard servers such as Apache Superset, Grafana and Metabase, commercial ones such as Power BI, Tableau and Looker Studio, notebook-based apps, and charting libraries such as matplotlib, seaborn, Vega-Altair, Plotly, ggplot2 in R and Observable Plot and D3 on the web. The principles in this lesson apply to all of them.

Writing the story with the numbers. The words around a chart do as much work as the chart. A few habits that experienced analysts share:

  • Lead with the answer. "Waits fell at four of six clinics, by 8 to 19 minutes; at the other two the change is too small to distinguish from noise." Then the evidence, then the caveats, then what you recommend.
  • Give numbers a scale. Absolute and relative together ("from 48 to 29 minutes, a 40% fall"), denominators ("64 patients recorded in February"), and comparisons people can feel ("about the length of a short bus ride").
  • Round for the reader. "19 minutes", not "19.27 minutes". Precision beyond what the uncertainty supports is noise that looks like knowledge.
  • Put uncertainty into words. "We are fairly confident the fall at Bela Vista was between 12 and 27 minutes" is understood by more people than "95% CI (−26.5, −12.3)"; give both if your audience includes analysts.
  • Separate what the data show from what you recommend. "Waits fell after online booking began" is a finding; "roll out online booking to all clinics" is a recommendation that also depends on cost, staff and patients without internet access, and it is better framed as "roll out in stages, so we can measure the effect" (see experiments in products).
  • Annotate. A short note on the chart ("online booking started 3 March") saves a paragraph of text and a misreading.

Analogy, not a formal construction

A good chart with a good headline works like a well-made road sign: it states one thing, in the place you need it, in a form you can read at speed. A dashboard of forty charts is a wall of signs; drivers ignore it.

Common misconceptionsH

Common misconceptions

Misconception

"Every axis must start at zero." Bars and areas must, because their length or area represents the value. Line charts and dot plots encode values by position, and zooming in to show variation is fine as long as the axis is labelled. What is never fine is a bar chart with a truncated axis.

Misconception

"Pie charts are always wrong." For two or three parts of a whole, where the message is "about a quarter" or "most", a pie is readable. With many slices, or when the reader must compare similar slices (as in this lesson's figure), it fails; a sorted bar chart does better.

Misconception

"More colours and more charts show more information." Beyond five or six categories, colours stop being distinguishable, and a page of charts competes for attention instead of answering a question. Show less, label directly, and use small multiples.

Misconception

"The chart speaks for itself." Readers bring different questions and see different things in the same chart. A title that states the finding, a subtitle that explains the encoding and a sentence of caveat make the chart say what the data support, and no more.

Exercises

Exercises

1. Visualisation and storytelling

Warm-upHuman

A transport authority wants to show how monthly public-transport journeys changed over the last three years in four cities, and whether the cities recovered at the same pace after a strike. Which chart is the best first choice?

Choose one

2. Visualisation and storytelling

CoreHuman

A bar chart compares two values, 50 and 55, but its vertical axis starts at 45. What is its lie factor (the relative change shown by the bars divided by the relative change in the data)?

3. Visualisation and storytelling

Warm-upHuman

In Cleveland and McGill's experiments, which way of encoding a quantity did people judge most accurately?

Choose one

4. Visualisation and storytelling

CoreHuman

Which of these practices make a chart more honest and readable? Select all that apply.

Choose all that apply

5. Visualisation and storytelling

CoreHuman

Which headline best fits the redesigned clinic chart (four clinics with falls of 8 to 19 minutes whose intervals exclude zero; two with small changes whose intervals include zero; no comparison clinics without online booking)?

Choose one

6. Visualisation and storytelling

CoreComputational

Write contrast_ratio(colour_a, colour_b) for colours given as "#rrggbb" (hex digits in either case). Following WCAG 2:

  1. convert each channel to [0,1][0, 1] by dividing by 255, then to linear light: c/12.92c/12.92 if c≤0.04045c \le 0.04045, else ((c+0.055)/1.055)2.4\left((c + 0.055)/1.055\right)^{2.4};
  2. relative luminance L=0.2126R+0.7152G+0.0722BL = 0.2126R + 0.7152G + 0.0722B;
  3. contrast ratio (Llighter+0.05)/(Ldarker+0.05)(L_{\text{lighter}} + 0.05) / (L_{\text{darker}} + 0.05), so the order of the arguments does not matter.

The tests check, among other things, that black on white is 21:1 and that #777777 on white just fails the 4.5:1 rule for text.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

7. Visualisation and storytelling

CoreComputational

Write text_bars(values, width=30), which draws an honest horizontal bar chart as a list of strings. values is a dict from label to a non-negative number. Return one line per item, sorted from largest to smallest value, each of the form

label.ljust(L) + " " + "#" * n + " " + str(value)

where L is the length of the longest label and n = round(width * value / largest), so bars are measured from zero and the largest bar has exactly width characters. If every value is 0, every bar is empty.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Further reading and resources