LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 35 lessons

Lesson 8 of 9

Module 2 · Figures that tell the truth

Publication-ready export

Publication-ready export

Publication-ready export

The last step decides whether a good figure stays good in print: size, resolution, file format, fonts and a description for readers who cannot see it.

⏱ 10 min readModule 2 · Figures that tell the truthFree
Lesson at a glance5 steps · about 10 min
  1. Vector or raster
  2. How to read the table below
  3. What this does
  4. A final checklist
  5. Why each item is there

Vector or raster

Every image file stores a picture in one of two ways. A vector file stores instructions: "draw a line from here to here, 0.5 points thick", "write the word Dose at this position in this font". The viewer redraws the shapes from those instructions at whatever size you look at them, so edges stay sharp however far you zoom in. A raster file stores a grid of coloured squares, called pixels. Enlarge it and the squares become visible, so diagonal lines turn into staircases and small text blurs.

Resolution for raster files is given in dpi, dots (pixels) per inch of printed size. The same 2,000-pixel-wide image prints sharp at 300 dpi if it fills about 6.7 inches, and looks blocky if it is stretched across a 20-inch poster. Plots are made of lines, points and text, which is exactly what vector formats describe well. Photographs and microscopy images are grids of measured light, so they are raster by nature.

Export is the last step, but it decides what every earlier choice looks like in the reader's hands. A figure built carefully in Multi-panel figures, at 180 mm and 8-point text, can still reach the page blurred or with its fonts replaced if it is saved in the wrong format. The reverse is also true: no export setting can rescue a figure drawn at the wrong size.

A common pitfall is to assume that a PDF is always vector. A PDF is a container, and it can hold a raster image just as easily as shapes. If you paste a screenshot into a slide and save the slide as PDF, or turn a PNG into a PDF, the plot inside is still a grid of pixels and will blur when enlarged. Only saving straight from matplotlib to PDF or SVG keeps the lines and text as shapes.

How to read the table below

Find the kind of picture you have in the "Use for" column, then read across to the format and what kind of file it is. Two terms need defining. Lossy compression, used by JPEG, makes files small by throwing away detail the eye is not supposed to miss; around sharp edges, such as text and thin lines, it leaves smudges and halos. PNG and TIFF can store pixels without losing anything (lossless), which is why they are acceptable for plots when a journal insists on raster files.

Publication-ready export · LSMA free course On the left, a diagonal line stored as a vector shape stays smooth when enlarged. On the right, the same line stored as pixels becomes a staircase of squares when enlarged. 1 · VECTOR, ENLARGED 2 · RASTER, ENLARGED Stored as a shape: sharp at any size Stored as pixels: steps show when enlarged PDF · SVG · EPS TIFF · PNG · JPEG
Both panels show the same diagonal line blown up many times. The vector version is redrawn smoothly from its description; the raster version can only show the squares it was saved with. Schematic, not to scale.
FormatTypeUse for
PDF, SVG, EPSVector: shapes, sharp at any sizePlots and diagrams; preferred by most journals
TIFF, PNGRaster: pixelsPhotographs and microscopy; plots when a journal asks for them, at 300–600 dpi
JPEGRaster, lossyNever for plots: compression blurs lines and text

EPS (Encapsulated PostScript) is an older vector format that some journals still list; PDF has largely replaced it. For a plot, the safe default is a PDF, plus a PNG or TIFF at the resolution the journal names if it also wants a raster file.

Python
import matplotlib.pyplot as plt

plt.rcParams.update({"font.size": 8, "pdf.fonttype": 42, "svg.fonttype": "none"})   # set before drawing

Now run the second code block of Multi-panel figures again, so the two-panel figure is redrawn with these defaults. In a new notebook, run that lesson's setup cell first. Then save the figure twice, as a vector PDF and as a 600 dpi PNG:

Python
fig.savefig("figure1.pdf", bbox_inches="tight")
fig.savefig("figure1.png", dpi=600, bbox_inches="tight")   # replaces the 300 dpi copy

What this does

  • plt.rcParams holds matplotlib's default settings, and .update({...}) changes several at once. Run it before any figure is drawn, because new text picks up the defaults when it is created. A figure that already exists keeps its old text sizes, which is why the figure is redrawn before it is saved.
  • "font.size": 8 makes 8 points the default text size, a common size for journal figures printed at their final width.
  • "pdf.fonttype": 42 tells matplotlib to embed fonts in PDFs as TrueType fonts ("type 42"), instead of its default, Type 3. Text then stays as editable text when the PDF is opened in a drawing program such as Illustrator or Inkscape, instead of turning into shapes that cannot be edited or searched.
  • "svg.fonttype": "none" does the same for SVG files: the labels are saved as real text, not as outlines of each letter.
  • fig.savefig("figure1.pdf", bbox_inches="tight") saves the vector version. bbox_inches="tight" trims empty margins around the figure, so it may come out slightly smaller than the figsize you set. No dpi is needed: a vector file has no pixels.
  • fig.savefig("figure1.png", dpi=600, bbox_inches="tight") saves a raster copy at 600 dots per inch. The file type is chosen from the ending of the file name, .pdf or .png.

Two details are worth knowing. First, bbox_inches="tight" changes the size of the saved file by trimming its margins. That is usually what you want, but if a journal asks for a figure exactly 85 mm wide, check the width of the saved file rather than trusting figsize. Second, the same rcParams mechanism sets the font itself, with "font.family". Many journals ask for a plain sans-serif font such as Arial or Helvetica, and setting it once at the top of the script keeps every panel consistent.

Check the files before you send them. Open the PDF and zoom in to several times its size: the lines and letters should stay sharp, and you should be able to select a word of the axis label with the cursor, which confirms the text was saved as text. For the PNG, check its size in pixels. Pillow, the image library that matplotlib itself relies on, does this in one line: from PIL import Image, then Image.open("figure1.png").size gives the width and height. The worked example below shows what numbers to expect.

Worked example · pixels needed

180 mm wide = 7.09 inches × 600 dpi = 4,252 pixels across
at 300 dpi: 2,126 pixels · a screenshot (about 1,000 pixels) is far too small for print

Step by step. Convert the width to inches first: 180 mm ÷ 25.4 mm per inch = 7.087 inches. Multiply by the dots per inch: 7.087 × 600 = 4,252 pixels. At 300 dpi it is half that, 7.087 × 300 = 2,126 pixels. A screenshot of a figure about 1,000 pixels wide, printed at 180 mm, would supply only about 1,000 ÷ 7.087 = 141 dots per inch, less than half of the lower requirement.

What the answer means. Resolution is pixels per inch of the printed size, so it only makes sense together with a width. "600 dpi" for a figure printed at 85 mm needs about half as many pixels as for one printed at 180 mm. This is another reason to design at the final size: the arithmetic, and the result, then match what the reader holds in their hand.

Go deeper: rasterising only the crowded layer

A volcano plot of 3,000 genes saved as a PDF stores 3,000 separate circles. That is fine, but a plot of 50,000 points, or a heatmap with thousands of cells, can make a vector file slow to open and many megabytes in size. matplotlib offers a middle way: mark the crowded layer with rasterized=True, as in ax.scatter(x, y, s=4, rasterized=True).

When you then save as PDF or SVG, only that layer is stored as pixels; the axes, tick labels, text and threshold lines stay as sharp vector shapes. The dpi you give to savefig now matters even for a PDF, because it sets the resolution of the rasterised layer: fig.savefig("volcano.pdf", dpi=600). The file stays small, the text stays editable, and at the printed size the points look the same as before.

Some journals ask for figures in CMYK, the cyan, magenta, yellow and black inks of a printing press, while matplotlib saves colours in RGB, the red, green and blue of a screen. A few bright screen colours cannot be printed exactly and come out duller. Most journals now convert the files themselves; if yours asks you to, convert at the very end and look at the result, because a palette chosen in Colour that works for everyone should still be distinguishable after conversion.

A final checklist

Each item below repeats a rule from an earlier lesson in this module. Read the checklist through once before you send any figure to a co-author or a journal.

The checklist is short on purpose. Most problems reviewers raise with figures are not subtle: missing units, unexplained error bars, unreadable text and colours that cannot be told apart. Catching them yourself takes a few minutes and saves a round of revision.

  • Saved at the final printed size; no text smaller than about 6–7 points.
  • Axis labels with units; panel letters; a legend explaining every symbol, error bar and colour.
  • Colour-blind-safe palette, and meaning not carried by colour alone.
  • Every bar chart starts at zero; scales match across compared panels.
  • The figure is made by a script, kept with the data, so it can be rebuilt.
  • Alt text for posters, web pages and slides: one or two sentences saying what the figure shows, not how it looks.

Why each item is there

  • Text size. One point is 1/72 of an inch, so 6 points is about 2 mm tall. Smaller than that, and labels become hard to read on a printed page.
  • Labels and legends. A reader who sees "Tooth length" without units cannot tell millimetres from micrometres, and an unexplained error bar could be a standard deviation, a standard error or a confidence interval (Comparisons and uncertainty).
  • Colour. About 1 in 12 men has a colour vision deficiency (Colour that works for everyone). Printing the figure in greyscale is a quick test: if two groups become the same grey, add a second cue, such as shape or position.
  • Scripts. When a reviewer asks you to remove one sample, a scripted figure is rebuilt in seconds; a hand-edited one has to be redrawn from memory.
  • Alt text (alternative text) is read aloud by screen readers for people who cannot see the image. "A bar chart in blue and orange" is no help. "Tooth length rises with vitamin C dose for both sources; orange juice gives longer teeth than ascorbic acid at the two lower doses" is.

The figure of about 1 in 12 men comes from surveys of people of European ancestry; Birch (2012), "Worldwide prevalence of red-green color deficiency", Journal of the Optical Society of America A 29(3), 313–320, reviews how the rate varies between populations. Alt text is required by the Web Content Accessibility Guidelines (WCAG) of the W3C, whose first success criterion asks for a text alternative for every image that carries information; see the W3C Web Accessibility Initiative. Journals set their own rules for figure width, file format, resolution and minimum text size, and these override any general checklist, including this one. Read the author guidelines of the journal you are submitting to before you export.

Template

Figure 1. (A) Tooth length in guinea pigs by vitamin C dose and source (n = 10 per group); points are individual animals and lines show group means. (B) Birth weight against mother's weight for 115 non-smokers and 74 smokers; lines are linear fits with 95% confidence bands.

Read the template the way a reviewer would. It names what was measured and in whom, gives the sample size for every group, and says what every mark on the figure means: points are animals, lines are means or fits, bands are 95% confidence intervals. A legend for the volcano plot from Omics figures would follow the same pattern: what each point is (one of 3,000 genes), what the axes show, what the dashed lines mark (adjusted p-value 0.05 and a log2 fold change of ±1), how many genes passed (76 up, 83 down), and that the data are simulated.

The next lesson, Remake a figure, is the module project. It asks you to take a weak figure and rebuild it, and this checklist is the standard to hold the result against.

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

Check your understanding

1. Which format keeps a plot sharp at any size?

2. Why save at the final printed size?

3. What should alt text describe?

Up next

Project

Remake a figure

Ask BioTutor

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