This page drills the parent recipe until no scenario can surprise you . We march through every knob — D ots, L etters, C olors — and every edge case each one hides.
Intuition Why a "scenario matrix" first?
A publication figure fails in only a handful of ways . If you list all the ways up front, then solve one example per way, you have literally covered the space. No exam twist lives outside the grid.
Throughout this page, DPI stands for dots per inch (DPI) — the number of pixels packed into one inch of the final printed figure. We define and re-derive it below before using it in the matrix.
Every figure problem lands in one of these cells. The examples below are tagged with the cell they hit. There are nine cells (A1–A4, L1, C1–C3, W1, X1) and nine examples (Ex 1–Ex 9) — one per cell, no gaps. (Here DPI = dots per inch.)
Cell
Knob
The scenario
Example
A1
Dots
figsize + DPI given → find pixels
Ex 1
A2
Dots
pixels + DPI given → find inches (inverse)
Ex 2
A3
Dots
degenerate : DPI raised but figsize left at default → font shrinks
Ex 3
A4
Dots
limiting : vector (PDF), DPI → "infinite"
Ex 4
L1
Letters
raw-string escape trap (\a, \n, \t)
Ex 5
C1
Colors
sequential map for low→high data (no centre)
Ex 6
C2
Colors
centred case : data has a meaningful zero centre → diverging
Ex 7
C3
Colors
grayscale / colorblind failure of jet
Ex 8
W1
Mixed
real-world word problem (double-column poster)
Ex 9a
X1
Mixed
exam twist: unit conversion cm → inches, physical font size
Ex 9b
We build the number tools before using them. Everything here is one multiplication or its inverse — see Dimensional analysis for why the units guide the arithmetic.
Definition Symbols and units used on this page
∣ ψ ∣ 2 — a probability density : any non-negative quantity that says "how much stuff is here." You do not need physics; treat it as a number ≥ 0 that we colour on a heatmap. The bars ∣ ⋅ ∣ mean "magnitude" so the value is never negative.
Δ T — a temperature anomaly (Greek capital delta Δ means "change from normal"): can be negative, zero, or positive.
pt (point) — a typographic unit of length, defined as 1 pt = 1/72 inch . This is the printing industry's fixed standard (a "pica point"); font sizes are always given in points. We take it as a definition, like "1 foot = 12 inches."
L (luminance) — the perceived brightness of a colour, i.e. what it becomes in grayscale. A standard recipe (Rec. 601) is L = 0.299 R + 0.587 G + 0.114 B for red/green/blue each in [ 0 , 1 ] ; the green weight is largest because the eye is most sensitive to green.
Figure 1 (below). A single 1-inch bar (blue arrow) holding D evenly spaced yellow dots — that is what "dots per inch" looks like . Four green boxes stacked left-to-right show w = 4 inches of width; the red arrow spans the full w inches. Counting all the yellow dots across those inches gives w ⋅ D pixels — the picture is the formula P x = w ⋅ D .
Figure 1: Stacking the per-inch dot count. Blue = one inch and its D dots; green = the w inches of width; red = the total width. Total dots across = w × D = pixels.
Look at the blue bar in the figure: it is 1 inch long and holds D dots. Stack w of them and you have w ⋅ D dots across. That is all multiplication is here — repeated stacking of the per-inch dot count.
Worked example Single-column figure
A journal column is 3.5 in wide, 2.6 in tall, printed at 300 dpi . How many pixels is the saved PNG?
Forecast: guess the width in pixels before reading on. More than 1000? Less?
Identify the knobs. w = 3.5 , h = 2.6 , D = 300 .
Why this step? You cannot plug into P = w D until every symbol has a number and a unit.
Multiply width. P x = 3.5 × 300 = 1050 .
Why? This is the frozen "per" doing its cancellation: inches × dots/inch = dots.
Multiply height. P y = 2.6 × 300 = 780 .
Why? Height uses the same DPI — DPI is one number for the whole image, not per axis.
Answer: 1050 × 780 px.
Verify: divide back — 1050/300 = 3.5 in, 780/300 = 2.6 in. Units return to inches, so the arithmetic is consistent.
Worked example You were given pixels, need inches
A collaborator sends a 1800 × 1200 px image and says it "must print at 600 dpi ." What physical size will it be on paper?
Forecast: at double the DPI of Ex 1, does the same pixel count give a bigger or smaller printed picture?
Rearrange the formula. From P x = w D solve w = P x / D .
Why this step? We know the product (pixels) and one factor (DPI); division is the tool that recovers the other factor. Division is the inverse of the multiplication in Ex 1.
Width. w = 1800/600 = 3.0 in.
Why divide, not multiply? Track the units: [ dots / inch ] [ dots ] = [ dots ] × [ dots ] [ inch ] = [ inch ] . The dots cancel and inches are left — the same cancellation as Ex 1, just run backwards. More dots crammed per inch means the same dots span fewer inches, so we divide.
Height. h = 1200/600 = 2.0 in.
Answer: 3.0 × 2.0 in.
Verify: forward-check 3.0 × 600 = 1800 ✓, 2.0 × 600 = 1200 ✓. And note the insight : high DPI shrinks the printed size for a fixed pixel count — the degenerate trap of Ex 3.
Worked example Why the label went tiny
A student wants a sharp figure so they write fig.savefig("f.png", dpi=600) but never set figsize, so it stays matplotlib's default 6.4 in wide. The journal column is only 3.5 in . The label font is 9 pt . How big does the font actually appear once the editor scales the image to fit the column?
Forecast: the student thinks bigger DPI = better. Will the reviewer be able to read the 9 pt label?
Font size lives in points, tied to inches. By the typographic definition above, 1 pt = 1/72 in, so a 9 pt label is drawn 9/72 = 0.125 in tall on the 6.4-in canvas .
Why this step? DPI never touched the point size — points are defined against inches , and the canvas is 6.4 in wide regardless of DPI.
The editor rescales to fit the column. Scale factor s = 3.5/6.4 = 0.547 .
Why? The whole 6.4-in drawing is squeezed into 3.5 in, so every length inside shrinks by the same ratio.
Apparent font size. 9 × 0.547 = 4.92 pt ≈ 5 pt.
Why multiply? Rescaling multiplies all internal lengths — including the font — by s .
Answer: the label prints at ~5 pt — below the ~7 pt legibility floor. DPI did not save it.
Verify: 3.5/6.4 = 0.5469 , and 9 × 0.5469 = 4.92 pt. Fix: set figsize=(3.5, 2.6) first , then font is 9 pt at true size. See Reproducible research and rcParams for locking this in a config block.
Common mistake "Just crank the DPI"
Feels right: more dots = sharper = better. Wrong: DPI is sharpness only; figsize is size. A high-DPI image squeezed to fit shrinks the whole drawing including text . Fix: figsize to the column width first, DPI second.
Worked example What DPI does a PDF need?
You have a line plot (axes, curves, LaTeX labels — no photo). You save it as fig.pdf. The reviewer asks "is it 300 or 600 dpi?" What do you answer?
Forecast: what happens to "pixels" as DPI → ∞ ?
Recall P = w D and push D → ∞ . lim D → ∞ w D = ∞ .
Why this step? A vector format (PDF/SVG) stores shapes (a line from point A to B ), not a grid of pixels. Rendering can regenerate pixels at any DPI on demand.
So DPI is undefined for the file itself. There is no fixed pixel grid to count.
Why? Only raster formats (PNG/TIFF) freeze a pixel grid; see Raster vs vector graphics .
Answer: "DPI is irrelevant — it's vector, sharp at any zoom." Use high-DPI raster only for photos/dense heatmaps.
Verify (sanity): P = w D is monotonically increasing in D with no upper bound, confirming the "infinite resolution" intuition — the limit diverges, so no single DPI number describes a PDF.
Worked example Which of these labels are corrupted?
A physicist writes three axis labels. Predict which render correctly before reading the steps.
ax.set_xlabel( "$ \a lpha$ decay" ) # (a)
ax.set_ylabel( "$ \t heta$ (rad)" ) # (b)
ax.set_title( "$ \n u$ frequency" ) # (c)
Forecast: which of (a), (b), (c) show garbage?
List Python's escape sequences. \a = bell (0x07), \t = tab, \n = newline, \r = return, \f, \v, \b... but \theta starts with \t.
Why this step? Python scans a normal string first , before matplotlib ever sees it. Any recognised escape is replaced silently.
Test each string.
(a) "$\alpha$" → \a becomes the bell char → $␇lpha$ — corrupted .
(b) "$\theta$" → \t becomes a tab → $ heta$ — corrupted .
(c) "$\nu$" → \n becomes a newline → label breaks into two lines — corrupted .
Why? Each backslash+letter matched a real escape.
The universal fix. Prefix r: r"$\alpha$", r"$\theta$", r"$\nu$". A raw string turns off escape processing so the backslash reaches LaTeX intact.
Why? See LaTeX typesetting — LaTeX needs the literal backslash to know \theta is a Greek letter command.
Answer: all three are corrupted without r; all three fix with r.
Verify: in Python, len("\alpha") is 5 (bell + lpha) while len(r"\alpha") is 6 (backslash + alpha). The length difference is the eaten backslash.
Worked example A density heatmap with no special centre
Dataset P is a probability density ∣ ψ ∣ 2 ∈ [ 0 , 1 ] — recall from the definitions box this is just a number ≥ 0 saying "how much stuff is here." It runs low → high with no meaningful middle value. Which colormap?
Forecast: does this data have a neutral centre, or does it just increase?
Ask the splitting question: is there a meaningful centre? For ∣ ψ ∣ 2 : no. Zero means "nothing here"; it is an endpoint , not a neutral middle.
Why this step? This one question decides sequential vs diverging for every colormap choice.
No centre ⇒ sequential. Use viridis: its brightness rises monotonically, so brighter = more density.
Why? A perceptually uniform sequential map sends equal data steps to equal perceived steps — honest reading.
Attach a labelled colorbar. cbar.set_label(r"$|\psi|^2$").
Why? Without the colorbar the colour scale is unreadable — it is the axis of colour.
Answer: Dataset P → viridis (sequential).
Verify (endpoint check): the data minimum 0 maps to the darkest end and the maximum 1 to the brightest; the midpoint value ( 0 + 1 ) /2 = 0.5 carries no special meaning, confirming a sequential (not diverging) choice. See Colormaps and color theory in visualization .
Worked example An anomaly heatmap with a meaningful zero
Dataset Q is a temperature anomaly Δ T ∈ [ − 4 , + 4 ] °C. Here Δ ("change from normal") means Δ T = 0 is the neutral reference — exactly average. Negatives are cooler, positives warmer. Which colormap?
Forecast: should the colour at Δ T = 0 be dark, bright, or neutral?
Ask the splitting question again. For Δ T : yes , there is a meaningful centre — the value 0 .
Why this step? This is the edge case that Ex 6 does not cover: a genuine neutral middle changes the answer.
Meaningful centre ⇒ diverging. Use coolwarm (blue–white–red) with the colour scale centred on zero , so 0 lands on neutral white.
Why? A diverging map places the neutral colour at the meaningful centre, so "above/below normal" reads at a glance.
Centre the limits symmetrically. Set the colour range to [ − 4 , + 4 ] (e.g. vmin=-4, vmax=4).
Why? If the limits were lopsided, white would drift off 0 and mislead the reader.
Answer: Dataset Q → coolwarm (diverging), centred on 0 .
Verify (centre check): the symmetric range [ − 4 , + 4 ] has midpoint ( − 4 + 4 ) /2 = 0 , which coincides with coolwarm's neutral colour — no false shift. Contrast with Ex 6, where the midpoint carried no meaning.
jet fails a colorblind reader
You must show a smooth gradient of values so the ordering is unambiguous. A reviewer prints your figure in grayscale . Compare jet and viridis on whether "which value is bigger?" stays answerable.
Forecast: does jet's bright yellow middle read as high or low in grayscale?
Convert each colormap to its luminance L . Using the Rec. 601 recipe from the definitions box, L = 0.299 R + 0.587 G + 0.114 B (each channel in [ 0 , 1 ] ) — this is exactly what a grayscale printer computes.
Why this step? A colorblind or grayscale reader has only L to go on. If L is not monotonic, order is lost.
jet: its L rises to a peak in the middle (bright yellow/cyan) then falls again toward dark red.
Why bad? Two different data values (a low blue and a high red) can share the same medium-gray L — the map is not one-to-one in brightness → fake edges , ambiguous order.
viridis: its L is monotonically increasing from dark purple to bright yellow.
Why good? Every brightness corresponds to exactly one value; grayscale preserves order perfectly.
Answer: viridis survives grayscale; jet does not.
Verify (monotonicity): sampling viridis luminance at 0 , 0.25 , 0.5 , 0.75 , 1.0 via the Rec. 601 formula gives a strictly increasing sequence (each larger than the last); jet does not — its middle sample exceeds an endpoint. The check confirms viridis is order-preserving, jet is not.
Worked example Sizing for a conference poster
A poster panel must be 7.0 in wide and 4.2 in tall, and the print shop demands 300 dpi minimum for crisp line art. (a) What pixel dimensions must the PNG be? (b) If you instead export PDF, what changes?
Forecast: will (a) be bigger or smaller than Ex 1's 1050×780?
Apply P = w D to each dimension. P x = 7.0 × 300 = 2100 , P y = 4.2 × 300 = 1260 .
Why this step? Same frozen "per" cancellation; larger inches → more pixels at the same DPI.
Check it beats the minimum. 300 dpi is the minimum, so exactly 2100 × 1260 px qualifies; going to 600 dpi (4200 × 2520 ) is safer for a big print.
Why? Posters are viewed close, so the shop's floor is a hard constraint, not a suggestion.
PDF variant. Export fig.pdf — pixel count no longer applies (Ex 4); the shop's RIP (raster image processor — the software inside the printer that turns vector shapes into the printer's own dot grid) renders it at whatever DPI the printer runs.
Why? Line art in vector is sharp at any size — ideal for large-format printing.
Answer: (a) 2100 × 1260 px at 300 dpi; (b) PDF removes the pixel constraint entirely — the printer's RIP supplies the dots.
Verify: 2100/300 = 7.0 in ✓, 1260/300 = 4.2 in ✓ — both recover the requested physical size.
Worked example The metric-column trap
An exam gives the column width in centimetres : 8.9 cm wide, and asks for the pixel width at 300 dpi . (1 in = 2.54 cm .)
Forecast: students who forget the conversion will get a wildly wrong answer. Bigger or smaller than the correct one?
Convert cm → in first. w = 8.9/2.54 = 3.504 in.
Why this step? The formula P = w D demands w in inches because D is dots per inch . Mixing units breaks the cancellation — Dimensional analysis is the guard.
Now multiply by DPI. P x = 3.504 × 300 = 1051.2 ≈ 1051 px.
Why round? Pixels are whole; matplotlib rounds to the nearest integer.
Spot the trap. A student who plugged 8.9 × 300 = 2670 treated centimetres as inches → answer 2.54 × too large.
Why? Feeding cm where inches belong scales the result by exactly the conversion factor 2.54 — the units never cancelled, so the "dots" you get are really "dots per (cm/inch)", a meaningless quantity.
Answer: ≈ 1051 px wide (essentially the same 3.5-in column as Ex 1 — because 8.9 cm is 3.5 in).
Verify: 8.9/2.54 = 3.5039 in, × 300 = 1051.2 ; the wrong answer 2670 = 1051.2 × 2.54 confirms the factor-of-2.54 error source.
Recall Every cell in one breath
DPI×inches=pixels (A1); divide to invert (A2); DPI without figsize shrinks fonts (A3); PDF = no DPI (A4); missing r eats backslashes (L1); low→high with no centre ⇒ sequential viridis (C1); meaningful zero centre ⇒ diverging coolwarm (C2); jet dies in grayscale, viridis lives (C3); convert cm→in before multiplying (X1).
D-L-C, forward and back
D ots multiply/divide with inches. L etters need the r. C olors: centre ⇒ diverge.
Ex 1 pixel width for 3.5 in at 300 dpi? 1050 px.
Ex 2 physical width for 1800 px at 600 dpi? 3.0 in (divide pixels by DPI).
Ex 3 apparent font size, 9 pt on 6.4-in canvas squeezed to 3.5 in? ≈ 4.9 pt (unreadable).
Ex 9b pixels for an 8.9 cm column at 300 dpi? ≈ 1051 px — convert cm→in first (8.9/2.54 = 3.5 in).
Which cell asks you to invert the formula? A2 — given pixels and DPI, solve w = P x / D .
Why is DPI meaningless for a PDF? It stores shapes, not a pixel grid (P = w D has no upper bound as D → ∞ ).
Sequential vs diverging: what decides? Whether the data has a meaningful centre — none ⇒ sequential (C1), zero centre ⇒ diverging (C2).
What is luminance L ? Perceived brightness / grayscale value, L = 0.299 R + 0.587 G + 0.114 B ; must rise monotonically for honest ordering.
Publication-quality figures — LaTeX labels, colormaps, DPI (index 5.4.19)
Matplotlib basics — figure and axes objects
Colormaps and color theory in visualization
LaTeX typesetting
Raster vs vector graphics
Dimensional analysis
Reproducible research and rcParams
pixels = inches times DPI