LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 35 lessons

Guided project

Module 2 · Figures that tell the truth · Self-checked

Remake a figure

Remake a figure

Remake a figure

A colleague's draft figure has every common problem. Rebuild it properly from the course files, in Python. Work through the six tasks, check each against its checkpoint, and tick it off. Nothing is submitted.

⏱ 9 min readModule 2 · Figures that tell the truth · Self-checkedFree
Lesson at a glance8 steps · about 9 min
  1. What is wrong with a draft like this
  2. How to approach this
  3. List the problems
  4. Panel A: the experiment
  5. Panel B: the volcano
  6. Panel C: the heatmap
  7. Assemble and export
  8. Legend and alt text

The draft

Panel 1: 3D bars of mean tooth length for the six groups, rainbow colours, y-axis starting at 5, ± SE bars, no units. Panel 2: a volcano plot in red and green, with all 159 significant genes labelled. Panel 3: a heatmap of raw expression values in the rainbow palette. Saved as a 72 dpi JPEG screenshot.

What is wrong with a draft like this

Nothing in the draft is unusual. Each choice is a default somewhere: 3D bars and rainbow colours are offered by spreadsheet programs, standard error bars are the shortest and so look tidy, and a screenshot is the quickest way to get a picture into a document. Each choice also hides or distorts something, and task 1 asks you to say what, and which lesson deals with it. Your job in this project is to rebuild the same three panels so that each one answers its question honestly.

Drafts like this are common in real work. A figure is often passed from one person to the next, each adding a panel in whatever program they had open, and nobody owns the whole. Learning to diagnose such a figure is as useful as learning to build a good one, because you will review far more figures than you make.

To diagnose a panel, look at each element in turn and ask two questions: what does this element make the reader believe, and is that belief supported by the data? Take the y-axis that starts at 5. From Comparisons and uncertainty and Choosing the right chart, the lowest group mean is 7.98 (ascorbic acid at 0.5 mg) and the highest 26.1 (2 mg). The true ratio is 26.1 ÷ 7.98, about 3.3. Drawn from 5, the bars are 26.1 − 5 = 21.1 and 7.98 − 5 = 2.98 units long, a ratio of about 7.1. The draft more than doubles the apparent effect before the 3D tilt and the rainbow colours have done anything. Work through every other phrase of the draft the same way.

How to approach this

  • Work in one script or notebook, from loading the files to saving the final PDF. If anything changes later, you rerun it from the top.
  • Set shared choices once, at the top: the colour dictionaries for the groups, the default font size, and the figure width in millimetres. Every panel then uses the same values.
  • Build one panel at a time, and check it against its checkpoint before you start the next. A wrong count in panel B is much easier to find before the panel is buried in a three-panel figure.
  • Reuse the code from the lessons. Every panel here was drawn, in a simpler form, earlier in the module. Your work is mostly combining and adjusting, not starting from nothing.
  • Look at the result at its printed size, on paper or zoomed to 100% on screen, before you decide it is finished.

Two more habits save time. First, when a panel will not behave, draw it on its own in a small figure of its own, get it right there, and only then move the code into the three-panel grid with ax=. Problems are much easier to see one panel at a time. Second, print the numbers each panel depends on before you plot them: the six group counts and means for panel A, the value_counts() of the status column for panel B, the shape of the z-scored table for panel C. If a printed number disagrees with its checkpoint, the figure will be wrong too, and the table is easier to debug than the picture.

Remake a figure · LSMA free course Task 1 lists the problems. Tasks 2 to 4 build panels A, B and C: a points plot, a volcano plot and a heatmap. Task 5 assembles them at 180 millimetres and exports PDF and PNG at 600 dpi. Task 6 adds the legend and alt text and checks greyscale. FROM DRAFT TO FINISHED FIGURE Task 1Tasks 2–4Task 5Task 6 List everyproblem andthe lessonthat fixes it Assembleat 180 mm;PDF, and PNGat 600 dpi LegendAlt textGreyscalecheck ABC pointsvolcanoheatmap one panel at a time
The six tasks follow the order a real figure is made in: diagnose, build each panel, assemble and export, then describe. Schematic, not to scale.
1

List the problems

Choosing the right chart · Showing distributions · Comparisons and uncertainty · Colour that works for everyone · Honest axes and scales

  • Write down every problem in the draft, and the lesson that fixes it.

Hint. Read the draft description phrase by phrase: almost every phrase hides one problem, and do not skip the last sentence, about the file. For each, ask which rule from Choosing the right chart to Honest axes and scales, or from Publication-ready export it breaks. Group them by panel so that tasks 2–4 can fix them one panel at a time.

Checkpoint: at least eight problems, including 3D, rainbow, truncated axis, SE bars without points, red–green, over-labelling, unscaled heatmap and the file format.

2

Panel A: the experiment

Choosing the right chart · Showing distributions · Comparisons and uncertainty

  • Tooth length by dose and source, every animal shown, with means and 95% confidence intervals, in Okabe–Ito colours.

Hint. Start from the strip plot of the tooth growth data in Choosing the right chart, which already shows every animal in the Okabe–Ito colours. Comparisons and uncertainty showed how to compute a mean and 95% confidence interval for each group and draw them on top of the points, in place of a bar with standard error bars. Keep the y-axis honest: points do not need to start at zero, but the range should include all the data.

Checkpoint: six groups of 10 points; at 2 mg the two sources overlap almost completely.

3

Panel B: the volcano

Colour that works for everyone · Omics figures

  • Volcano plot of de_results_example.csv in blue and orange, with threshold lines, labelling only the five genes with the smallest adjusted p-values.

Hint. The volcano code in Omics figures already gives the colours, the status counts and the threshold lines. To choose the five genes to label, sort the results table by adjusted p-value and take the first five rows; label only those, with short lines to their points if they crowd together. The adjustText package mentioned in Omics figures can move labels apart for you.

Checkpoint: 76 up and 83 down; five labels that do not overlap.

4

Panel C: the heatmap

Colour that works for everyone · Omics figures

  • Clustered heatmap of expression_example.csv, z-scored by gene, diverging palette centred on zero, with a group colour bar.

Hint. Colour that works for everyone z-scored the expression table by gene, and Omics figures drew it with sns.clustermap, a diverging palette centred on zero and a group colour bar. Remember that clustermap builds a whole figure of its own, so it cannot be placed into one panel with ax=. Plan for this before task 5: one way is to let it work out the clustered order of genes and samples, then draw the reordered table into your panel with an axes-level heatmap.

Checkpoint: samples split into control and treated; two blocks of six genes change in opposite directions.

5

Assemble and export

Multi-panel figures · Publication-ready export

  • Combine the panels with letters A–C at 180 mm wide; save as PDF and as PNG at 600 dpi.

Hint. Multi-panel figures shows how to set the figure width in millimetres and add panel letters with transform=ax.transAxes. Publication-ready export gives the export settings and the arithmetic for pixel width. Three panels in one row at 180 mm leave each about 60 mm, so consider whether the heatmap needs more room than the other two.

Checkpoint: the PNG is about 4,250 pixels wide (a little less from Python with bbox_inches="tight", which trims the margins), and all text is still readable when the figure is printed at 180 mm.

6

Legend and alt text

Publication-ready export

  • Write the figure legend and two sentences of alt text.
  • Check the figure in greyscale.

Hint. Use the legend template at the end of Publication-ready export as a pattern: say what was measured and in whom, the number in each group, and what every point, line, colour and error bar means. For the greyscale check, view the PNG in any image viewer or print preview set to greyscale, and ask whether every group can still be told apart.

Checkpoint: the legend explains every point, line, colour and error bar; the figure still reads in greyscale.

Go deeper: getting the clustered order out of clustermap

Task 4 needs a heatmap inside one panel, but sns.clustermap always makes its own figure. Its result remembers the order it chose, though. After cg = sns.clustermap(z, cmap="RdBu_r", center=0), the lists rows = cg.dendrogram_row.reordered_ind and cols = cg.dendrogram_col.reordered_ind hold the row and column positions in clustered order.

z.iloc[rows, cols] is the table rearranged the same way, and an axes-level call, sns.heatmap(z.iloc[rows, cols], cmap="RdBu_r", center=0, ax=axes[2]), draws it into your own panel. Close the extra figure with plt.close(cg.figure) so it is not shown or saved by mistake. The trade-off is that the trees are no longer drawn, so say in the legend that rows and columns were ordered by hierarchical clustering, and name the distance and linkage (by default, Euclidean and average). If you want a tree as well, SciPy's scipy.cluster.hierarchy.dendrogram can draw one into an axes of its own.

When all six tasks are done, hold the finished figure against the checklist in Publication-ready export, item by item. Then compare it with the draft description at the top of this page. Every problem you listed in task 1 should now be fixed or deliberately accepted, with a reason you could give a reviewer. The finished figure is not only prettier: each panel now lets a reader check the claim it makes, which is the point of the whole module.

Take it further

Apply the checklist to a figure from your own work. Then use it on the figures you make in Module 4: machine learning.

In the next module, Coding with AI assistants, you will start writing and checking code with an AI assistant: asking it well, reading what it writes before you run it, testing and debugging it, and using it responsibly. An assistant will happily produce plotting code for any of the panels in this project, and much of that code will run. Whether the figure it draws is honest is a judgement it cannot make for you. The rules you applied here, about chart choice, error bars, colour, axes and export, are exactly what lets you check its output.

End of Module 2: Figures that tell the truthYou can stop here: this module is complete on its own. Or carry on to Module 3, Coding with AI assistants (Intermediate).

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

Up next

Lesson 1

What AI coding assistants are

Ask BioTutor

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