5.4.19Scientific Computing (Python)

Publication-quality figures — LaTeX labels, colormaps, DPI

1,769 words8 min readdifficulty · medium

1. DPI — what "resolution" actually means

WHY does this matter? Journals specify a column width in inches (e.g. 3.5 in) AND a minimum DPI (often 300 for line art, 600 for fine detail). If you only set pixel size you have no control over how big text looks on the page.


2. LaTeX / math labels

WHY raw strings? In a normal string "\lambda"\l is not a known escape but "\n" is a newline. Using r"..." guarantees backslashes reach LaTeX untouched.


3. Colormaps — perceptual uniformity

Figure — Publication-quality figures — LaTeX labels, colormaps, DPI

4. Putting it together (the full recipe)

Recall Feynman: explain to a 12-year-old

Imagine drawing a picture to put in a real book. DPI is how many tiny dots you cram in per inch — too few and the picture looks blocky like Minecraft. LaTeX labels make the words and math in your picture match the fancy fonts in the book so it doesn't look out of place. Colormaps are the rule for turning numbers into colors — a good rule paints big numbers brighter step by step, so your eye reads the picture honestly instead of getting tricked by a flashy rainbow.


Common mistakes


Flashcards

A 3.5 in × 2.6 in figure saved at dpi=300 has how many pixels?
1050×7801050 \times 780 px (multiply each inch dimension by 300).
Why prefer viridis over jet?
viridis is perceptually uniform (monotonic brightness), grayscale-safe and colorblind-friendly; jet creates false edges and fails in grayscale.
What does the leading r in r"$\lambda$" do?
Makes a raw string so Python doesn't interpret backslash escapes; the \lambda reaches LaTeX intact.
Difference between sequential and diverging colormaps?
Sequential for low→high data (viridis); diverging for data with a meaningful center/zero, mapping center to a neutral color (coolwarm).
Why save line plots as PDF instead of PNG?
PDF is vector — stores shapes not pixels, so it's sharp at any zoom and DPI is irrelevant; PNG is raster and depends on DPI.
What sets the physical printed size of a figure?
figsize (in inches), not DPI. DPI only sets sharpness at that size.
When must you set figsize before font sizes?
Always — fonts are in points (1/72 in), so the inch canvas determines how big text looks on the page.
What is text.usetex=True for vs default mathtext?
usetex hands rendering to a real LaTeX install (exact paper fonts); mathtext is matplotlib's built-in TeX-like engine, no external LaTeX needed.

Connections

  • Matplotlib basics — figure and axes objects
  • Colormaps and color theory in visualization
  • LaTeX typesetting
  • Raster vs vector graphics
  • Dimensional analysis
  • Reproducible research and rcParams

Concept Map

needs

needs

needs

option A

option B

requires

protects

use

survives

fixes physical size

multiplied with

keeps point sizes true

Publication-quality figure

Text rendering

Colormap

DPI resolution

figsize in inches

Pixel count

text.usetex=True

mathtext engine

Raw string r-prefix

Perceptually uniform viridis

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, ek figure ko "publication-quality" banane ke liye sirf teen cheezein control karni hoti hain — main inhe D-L-C bolta hun: Dots (DPI), Letters (LaTeX labels), aur Colors (colormap). DPI matlab kitne pixels ek inch me bharein hain. Yaad rakho: figsize aapke figure ka asli physical size inches me set karta hai, aur dpi sirf sharpness. Agar tum sirf dpi=600 kar do par figsize default chhod do, toh column me figure shrink ho jaayega aur 9-point font 5-point jaisa dikhega — illegible. Isliye pehle figsize (journal ki column width, jaise 3.5 inch) set karo, phir dpi.

Letters ka matlab — agar tum text.usetex=True karte ho toh asli LaTeX se text render hota hai, jisse fonts bilkul tumhare paper ke jaise match karte hain. Math likhne ke liye $...$ use karo, aur string ke aage r lagao (r"$\lambda$") taaki Python backslash ko kharab na kare. Yeh raw string wali galti bahut common hai.

Colors sabse zyada log galti karte hain. jet (rainbow) bahut colourful lagta hai isliye accha lagta hai, par yeh dhokha deta hai — beech me bright yellow band fake edges bana deta hai aur grayscale ya colorblind logon ke liye useless ho jaata hai. Iski jagah viridis use karo — yeh perceptually uniform hai, matlab data ki value jaise badhti hai brightness bhi waise hi smoothly badhti hai. Agar data ka meaningful center hai (jaise +/- anomaly) toh coolwarm jaisa diverging colormap lo. Aur har colormap ke saath ek labeled colorbar zaroor lagao, warna color ka matlab kisi ko samajh nahi aayega. Last tip: line plots ko PDF me save karo (vector, infinite sharpness), aur dense heatmaps/photos ko PNG/TIFF me high DPI par.

Go deeper — visual, from zero

Test yourself — Scientific Computing (Python)

Connections