LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 35 lessons

Lesson 5 of 9

Module 2 · Figures that tell the truth

Honest axes and scales

Honest axes and scales

Honest axes and scales

The same numbers can look like a small difference or a huge one, depending on where the axis starts. Readers trust that you chose fairly.

⏱ 12 min readModule 2 · Figures that tell the truthFree
Lesson at a glance6 steps · about 12 min
  1. The same two numbers, drawn twice
  2. What this does
  3. Reading the output
  4. Rules that keep scales honest
  5. Why each rule holds
  6. What this does

The same two numbers, drawn twice

An axis is the ruler along the edge of a plot. The scale is the rule that turns a value into a position on that ruler: where it starts, where it ends, and whether equal steps add the same amount (a linear scale) or multiply by the same amount (a log scale). Readers rarely check these choices. They look at the shapes and assume the shapes are fair.

That trust is why axes deserve care. In Colour that works for everyone you saw that the limits of a colour scale decide what looks extreme in a heatmap. The limits of an x or y axis do the same job for position and length, and they are easier to change without anyone noticing.

The code below uses the tooth growth data from Choosing the right chart (tg): sixty guinea pigs, ten per group, given vitamin C as orange juice or as ascorbic acid. It takes only the animals on the 1 mg dose, works out the mean tooth length for each source, and draws the same two means twice, once with the axis starting at 15 and once at 0.

Python
d1 = tg[tg["dose"] == 1].groupby("supp")["len"].mean()
print(d1.round(2))

fig, axes = plt.subplots(1, 2, figsize=(8, 3.4))
for ax, bottom, title in [(axes[0], 15, "Axis starts at 15 (misleading)"), (axes[1], 0, "Axis starts at 0")]:
    ax.bar(d1.index, d1.values, color=["#0072B2", "#E69F00"])
    ax.set_ylim(bottom, 25)
    ax.set_title(title, loc="left", fontsize=11)
    ax.set_ylabel("Mean tooth length (dose 1)")
sns.despine()
plt.tight_layout()
supp Ascorbic acid 16.77 Orange juice 22.70 Name: len, dtype: float64

What this does

  • tg["dose"] == 1 compares every row's dose with 1 and gives a column of True and False. Putting that inside tg[ ] keeps only the True rows: the 20 animals on 1 mg a day.
  • .groupby("supp")["len"].mean() splits those rows by supplement, takes the tooth length column, and averages it within each group. The result, d1, is a pandas Series: a column of numbers with a label for each value, here the two supplement names.
  • print(d1.round(2)) shows the two means rounded to two decimal places.
  • plt.subplots(1, 2, figsize=(8, 3.4)) makes one figure with one row of two plotting areas, 8 inches wide and 3.4 inches tall. axes holds the two areas, axes[0] on the left and axes[1] on the right.
  • The for loop runs twice. Each item in the list is a group of three: which plotting area to use, where the axis should start, and the title. The first pass draws the left chart from 15; the second draws the right chart from 0.
  • ax.bar(d1.index, d1.values, ...) draws one bar per supplement, with the height set by the mean. The two colours are taken in order: blue (#0072B2) for the first bar, ascorbic acid, and orange (#E69F00) for the second, orange juice, matching the colours used for these groups in earlier lessons.
  • ax.set_ylim(bottom, 25) is the line that matters. It sets where the y-axis starts and ends. Everything else in the two charts is identical.
  • set_title(..., loc="left") places the title at the left edge, and set_ylabel labels the axis. sns.despine() removes the top and right border lines from both plots, and plt.tight_layout() adjusts the spacing so labels do not collide.

Reading the output

The first line, supp, is the name of the column the groups came from. The next two lines are the groups and their means: 16.77 for ascorbic acid and 22.70 for orange juice. pandas lists the groups in alphabetical order, which is why ascorbic acid comes first. The last line says the values came from the len column and are stored as float64, a standard decimal number type. These two means are all that the charts below draw.

Two bar charts of the same means. With the axis starting at 15, the orange juice bar looks four times taller. With the axis starting at 0, it is about one third taller.
The same two numbers, drawn with two different axes.

Look at the left chart first. The ascorbic acid bar is a stub and the orange juice bar towers over it, so the eye reads "orange juice works several times better". Now look at the right chart: the orange juice bar is taller, but clearly by about a third. The data are the same. Only the start of the axis moved.

In matplotlib, a bar chart starts at zero unless you set the limits yourself, as this code does with set_ylim. Some other programs zoom in on the data automatically, so a truncated bar chart can reach you from a colleague, a slide deck or a paper without anyone having chosen it on purpose. When you read a bar chart, look at the lowest tick label before you look at the bars.

The reason is that a bar shows its value through its length. Readers compare lengths almost without thinking, and a bar's length is measured from where the axis starts. When the axis starts at 15, the bar for 16.77 is drawn only 1.77 units long, and the bar for 22.70 is drawn 7.70 units long. The worked example below turns that into a number.

Worked example · how much a truncated axis exaggerates

true ratio = 22.70 ÷ 16.77 = 1.35 (35% longer)
drawn from 15: (22.70 − 15) ÷ (16.77 − 15) = 7.70 ÷ 1.77 = 4.35
the left chart makes the difference look about three times larger than it is

Step by step. The true ratio compares the two means directly: 22.70 ÷ 16.77 = 1.354, which rounds to 1.35. So orange juice gives teeth about 35% longer than ascorbic acid at this dose. On the truncated chart, each bar's drawn length is its value minus the axis start of 15: 22.70 − 15 = 7.70 and 16.77 − 15 = 1.77. The drawn ratio is 7.70 ÷ 1.77 = 4.35. Comparing the two ratios, 4.35 ÷ 1.35 is about 3.2, so the picture exaggerates the difference about three times.

What the answer means. Nothing in the left chart is false: every tick mark is in the right place. The distortion comes from what the eye does with bar lengths. A reader who glances at it, as most readers do, carries away a ratio of more than four to one when the data support about 1.35 to one.

Go deeper: Tufte's lie factor

The statistician Edward Tufte proposed a single number for this kind of distortion in his 1983 book The Visual Display of Quantitative Information. The lie factor is the size of an effect as drawn divided by its size in the data, where the size of an effect is the change from the first value to the second, as a share of the first.

In the data, the change from 16.77 to 22.70 is 5.93 ÷ 16.77 = 0.354, an increase of about 35%. As drawn, the bars grow from 1.77 to 7.70 units, a change of 5.93 ÷ 1.77 = 3.35, an increase of 335%. The lie factor is 3.35 ÷ 0.354, about 9.5. That is larger than the "about three times" in the worked example because the two compare different things: the lesson compares ratios of bar lengths, while the lie factor compares percentage changes, which soar as the shorter bar shrinks towards nothing. Tufte suggested that a lie factor below 0.95 or above 1.05 signals a real distortion.

Rules that keep scales honest

  • Bars start at zero. Points and lines need not, because their position, not their length, carries the value.
  • Use log scales for values spanning orders of magnitude, such as read counts (3 to 31,540 in de_results_example.csv) and fold changes, where ×2 and ×½ should look equally large. Label the axis as log.
  • Keep scales the same across panels that will be compared (sharey=True in plt.subplots; seaborn's catplot and relplot share axes by default).
  • Avoid two y-axes on one plot: the apparent relationship depends entirely on how each axis is scaled. Use two panels instead.

Why each rule holds

Bars and zero. A bar is a length, and a length only means something if it is measured from zero. A point or a line is different: what you read is its position against the tick marks, so a point plot can be zoomed in on a narrow range without implying a false ratio. That is why Comparisons and uncertainty replaced bars with points and intervals.

Log scales. On a log scale, equal distances stand for equal ratios. The step from 10 to 100 is the same width as the step from 100 to 1,000, because each is a ×10. Read counts from 3 to 31,540 span about four powers of ten. On a linear axis, every gene below a few hundred would be squashed into a thin strip next to zero, and only the handful of very high counts would be visible. Fold changes have a related problem: a doubling (×2) and a halving (×½) are equally large effects in opposite directions, but on a linear axis the doubling sits 1 unit above "no change" (1) and the halving only 0.5 below it. Taking the log base 2 turns them into +1 and −1, which is why results tables report log2FoldChange.

How you apply the log also matters. For a histogram, seaborn's sns.histplot(..., log_scale=True) makes the bins equally wide on the log scale, so each bar covers the same ratio of values. Drawing an ordinary histogram and then calling ax.set_xscale("log") gives a different picture: the bins were made equally wide on the linear scale, so on the log axis they look narrow at the right and wide at the left, and the shape is hard to read. Choose the scale before the bins are made, not after.

One practical catch: the log of zero is not defined, so a count of 0 cannot be placed on a log axis. Analyses that need to show zeros usually add a small constant, such as 1, to every count before taking the log, and say so in the axis label or legend.

In code that is np.log2(counts + 1), often called a pseudocount of 1. The constant changes small values much more than large ones: a count of 1 becomes 1 on the log2 scale instead of 0, while 31,540 hardly moves. So differences among very low counts on such a plot should be read with caution.

Same scales across panels. If panel A runs from 0 to 30 and panel B from 0 to 10, two dots at the same height mean different things, and readers will compare them anyway. sharey=True in plt.subplots makes all panels in a row use one y-axis. Seaborn's figure-level functions, such as catplot and relplot, also share one y-axis across panels unless you ask otherwise.

Two y-axes. With a second y-axis on the right, you can make two unrelated curves appear to rise together, or to cross at any point you like, only by choosing where each axis starts and ends. Since the reader cannot tell which of these choices was made fairly, the safer design is two panels, one above the other, sharing the x-axis.

All four rules come back to the same test. Imagine a reader who looks at the figure for five seconds and never reads a tick label. Would their impression match the numbers? If the answer depends on noticing where an axis starts, how it is spaced or which side it belongs to, change the design rather than relying on the reader to notice.

Python
# log scale
ax.set_yscale("log")                     # or sns.scatterplot(...).set(yscale="log")

What this does

ax.set_yscale("log") tells an existing plotting area, ax, to space its y-axis by powers of ten instead of by equal steps. The data are not changed; only the drawing is. The comment shows the same setting for a seaborn plot: seaborn functions such as sns.scatterplot return the plotting area they drew on, so you can call .set(yscale="log") on the result directly. Matplotlib then labels the ticks 100, 101, 102 and so on, which already tells the reader the axis is logarithmic; adding "(log scale)" to the axis label makes it unmistakable.

One caution with shared axes and log scales together: if any panel contains a zero or negative value, matplotlib cannot place it on a log axis and will leave it out, sometimes with only a warning. Check the number of points drawn against the number in your table. The next lesson, Multi-panel figures, puts several plots into one figure, where these choices about shared and matching scales matter most.

Honest axes and scales · LSMA free course The counts 3, 30, 300, 3,000 and 30,000 are placed on two axes. On the linear axis the first three overlap at the far left. On the log axis all five are evenly spaced, because each is ten times the one before. 1 · LINEAR AXIS: EQUAL STEPS ADD 10,000 3, 30 and 300 overlap at the far left 3,000 30,000 010,00020,00030,000 2 · LOG AXIS: EQUAL STEPS MULTIPLY BY 10 3303003,00030,000 1101001,00010,000100,000 Each tick is ten times the one before, so ×10 always covers the same distance.
Five example counts, each ten times the last. On the linear axis (top) the three smallest are squeezed into one blob next to zero; on the log axis (bottom) every one gets the same room. Schematic, not to scale.

Wainer (1984), "How to display data badly", The American Statistician 38(2), 137–147, is a classic, readable catalogue of the tricks covered in this lesson, including axes that do not start at zero and scales that change partway along. For log axes in Python, see the matplotlib documentation for set_yscale, which also offers "symlog": a scale that is linear close to zero and logarithmic further out, useful when data contain zeros or negative values. The rule that bars start at zero is widely agreed. For points and lines, authors differ on how far an axis may be zoomed in, so let the question set the range, and say in the legend when an axis is logarithmic or broken.

Key point

If you must zoom in on a bar chart, switch to points, or mark the break in the axis clearly. Never let the drawing imply a ratio the data do not support.

A second example of the same idea. Suppose two groups have mean values of 98 and 100, and the bars are drawn from an axis starting at 95. The bars are 3 and 5 units long, so the second looks two-thirds taller, although the real difference is 2%. Drawn as two points with confidence intervals on an axis from 95 to 101, the same values are honest: the reader reads positions against the tick marks, and the closeness of the two points is plain to see.

Further reading · Module 2Weissgerber et al. 2015: why bar charts hide the data. · All reading for this course

Check your understanding

1. Values 50 and 55, bars drawn from 45. How many times taller does the second bar look?

2. Which data most need a log scale?

3. Why avoid two y-axes on one plot?

Up next

Lesson 6

Multi-panel figures

Ask BioTutor

Create a free website with Framer, the website builder loved by startups, designers and agencies.