5.4.19 · D3Scientific Computing (Python)

Worked examples — Publication-quality figures — LaTeX labels, colormaps, DPI

3,600 words16 min readBack to topic

This page drills the parent recipe until no scenario can surprise you. We march through every knob — Dots, Letters, Colors — and every edge case each one hides.

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.


The scenario 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.


The one formula, earned

Figure 1 (below). A single 1-inch bar (blue arrow) holding evenly spaced yellow dots — that is what "dots per inch" looks like. Four green boxes stacked left-to-right show inches of width; the red arrow spans the full inches. Counting all the yellow dots across those inches gives pixels — the picture is the formula .

Figure — Publication-quality figures — LaTeX labels, colormaps, DPI
Figure 1: Stacking the per-inch dot count. Blue = one inch and its dots; green = the inches of width; red = the total width. Total dots across = = pixels.

Look at the blue bar in the figure: it is 1 inch long and holds dots. Stack of them and you have dots across. That is all multiplication is here — repeated stacking of the per-inch dot count.


Ex 1 — Cell A1: the forward calculation


Ex 2 — Cell A2: running the formula backwards


Ex 3 — Cell A3: the degenerate "cranked DPI" mistake


Ex 4 — Cell A4: the limiting case, vector output


Ex 5 — Cell L1: the raw-string escape trap


Ex 6 — Cell C1: sequential map for low→high data


Ex 7 — Cell C2: the centred case → diverging map


Ex 8 — Cell C3: the grayscale / colorblind test


Ex 9a — Cell W1: the double-column poster (word problem)


Ex 9b — Cell X1: the exam twist (cm → inch conversion)


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).


Self-check

Ex 1 pixel width for 3.5 in at 300 dpi?
px.
Ex 2 physical width for 1800 px at 600 dpi?
in (divide pixels by DPI).
Ex 3 apparent font size, 9 pt on 6.4-in canvas squeezed to 3.5 in?
pt (unreadable).
Ex 9b pixels for an 8.9 cm column at 300 dpi?
px — convert cm→in first ( in).
Which cell asks you to invert the formula?
A2 — given pixels and DPI, solve .
Why is DPI meaningless for a PDF?
It stores shapes, not a pixel grid ( has no upper bound as ).
Sequential vs diverging: what decides?
Whether the data has a meaningful centre — none ⇒ sequential (C1), zero centre ⇒ diverging (C2).
What is luminance ?
Perceived brightness / grayscale value, ; must rise monotonically for honest ordering.

Connections

  • 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

A1 A2

L1 raw string

C1 C2 C3

forward

inverse

centre in data

low to high

Scenario matrix

Dots cell

Letters cell

Colors cell

pixels = inches times DPI

inches = pixels over DPI

diverging coolwarm

sequential viridis