Figure Library
The group maintains two small packages of plotting defaults with matching functions, so that group figures share a colorblind-safe palette and readable type without each project setting them up again:
They implement a few recommendations from Figure Design, which explains the reasoning behind them.
Yes. Figure Design says that visualization depends on context and that breaking its guidelines sometimes gives a better figure, and the same goes for these defaults. They save you from setting up a palette and fonts for every figure when those aren’t the question you’re working on.
Getting Started
using Pkg
Pkg.add(url = "https://github.com/srikrishnan-lab/VizLab.jl")using VizLab, Plots
lab_theme!() # once, at the top of a figure script
p = plot(size = journal_size(:single))
spaghetti!(p, years, ensemble; n = 100)
bandplot!(p, years, q05, q95; label = "5–95% ensemble range")
savefig(p, "figures/fig01_slr.png")pip install git+https://github.com/srikrishnan-lab/vizlab-pyimport matplotlib.pyplot as plt
import vizlab
vizlab.lab_theme() # once, at the top of a figure script
fig, ax = plt.subplots(figsize=vizlab.journal_size("single"))
vizlab.spaghetti(ax, years, ensemble, n=100)
vizlab.bandplot(ax, years, q05, q95, label="5-95% ensemble range")
fig.savefig("figures/fig01_slr.png")What the Packages Contain
| Function | What it does |
|---|---|
lab_theme |
Readable fonts, no top/right spines, light y-grid only, colorblind-safe palette |
lab_palette(n) |
Colorblind-safe categorical colors; warns past about 7 |
sequential() / diverging() |
Colormaps for magnitudes and for data with a meaningful midpoint |
bandplot |
Shaded uncertainty interval |
spaghetti |
Subsampled ensemble members |
journal_size |
Single, one-and-a-half, and double column widths |
The palettes are Paul Tol’s bright and muted schemes, which are designed to stay distinguishable for readers with the common forms of color-vision deficiency. They are not distinguishable in grayscale (in the bright scheme, blue and green have almost the same lightness), so if a figure has to work in grayscale, vary the line style or marker as well as the color.
lab_palette warns past about seven categories because beyond that, readers have trouble telling hues apart. Use facets or label the lines directly instead.
Three Common Figure Errors
The package docstrings warn about three errors that are easy to miss before publication:
- Not saying what an uncertainty band is. A 90% credible interval, a 5–95% ensemble range, and one standard error look identical on the page and mean very different things, so the caption has to say which one is shown.
- Using a diverging colormap with limits that aren’t symmetric around the midpoint. If the midpoint of the color scale isn’t the midpoint of interest in the data, the figure suggests a center that isn’t there.
- Scaling a figure after creating it. Set the figure size when you create it, because scaling afterwards changes the physical font size, which is one way axis labels end up too small to read in print.
Ensemble Spaghetti
spaghetti subsamples members by default, because plotting several thousand translucent lines produces a solid block with no visible structure.
While you are exploring results, plot both the individual members and the summary band, since they show different things. The band shows where most of the probability is; the individual lines show whether the ensemble does something a band hides, such as bimodality, crossing trajectories, or members that behave qualitatively differently. Figure Design makes the same point about representations of uncertainty in general.
Archiving
A paper’s figures have to regenerate years after publication. If your figure scripts import a package that keeps changing, they will eventually stop reproducing the published figures, and the archive your availability statement points to will no longer match the paper.
Either pin the version in your project’s Manifest.toml or environment file (which the meta-repository archives anyway), or copy the theme function into the paper’s repository.
Makie
Makie.jl is the alternative to Plots.jl, and the better choice when you need interactivity, 3D, or fine control over complex multi-panel layouts. Several group projects already use CairoMakie.
The palettes are plain hex strings, so they work in Makie unchanged:
using CairoMakie, VizLab
set_theme!(palette = (color = VizLab.TOL_BRIGHT,), fontsize = 10)The helper functions only work with Plots.jl. If you find yourself rewriting them for Makie, please open an issue instead of keeping a private copy; if more than one project needs them, we can add a Makie extension.
Adding to the Packages
Additions are welcome, especially for plot types the group makes often. The two packages should keep matching functions, so that switching languages doesn’t mean learning a new set of defaults.