Programmatic Figure Generation

Reproducible Figure Scripts

Every figure in a paper should be generated by a script, never by manual GUI interaction. A figure generation script takes simulation data as input and produces a publication-ready PDF as output. This makes figures reproducible, version-controllable, and trivially updatable when simulations are re-run.

Definition:

Anatomy of a Figure Generation Script

A well-structured figure generation script has four parts:

# 1. Configuration
STYLE = {'font.family': 'serif', 'font.size': 8, ...}
OUTPUT_DIR = Path('figures/')

# 2. Data loading
df = pd.read_csv('results/ber_sweep.csv')

# 3. Plotting
def make_ber_figure(df):
    fig, ax = plt.subplots(figsize=(3.5, 2.5))
    # ... plotting code ...
    return fig

# 4. Export
if __name__ == '__main__':
    plt.rcParams.update(STYLE)
    fig = make_ber_figure(df)
    fig.savefig(OUTPUT_DIR / 'ber.pdf', bbox_inches='tight')

Definition:

Makefile for Automated Paper Building

A Makefile orchestrates simulation, figure generation, and LaTeX compilation:

FIGURES = figures/ber.pdf figures/constellation.pdf
TABLES  = tables/results.tex

paper.pdf: paper.tex (FIGURES)(FIGURES)(TABLES)
    pdflatex paper.tex
    bibtex paper
    pdflatex paper.tex

figures/ber.pdf: scripts/plot_ber.py results/ber.csv
    python scripts/plot_ber.py

tables/results.tex: scripts/gen_tables.py results/sim.csv
    python scripts/gen_tables.py

results/ber.csv: scripts/simulate.py
    python scripts/simulate.py

Theorem: Simulation-Visualization Separation

A reproducible paper separates three concerns:

  1. Simulation β†’\to produces raw data (CSV, HDF5, NumPy)
  2. Visualization β†’\to reads raw data, produces figures (PDF, PGF)
  3. Document β†’\to includes figures and tables, produces paper

Changes to visualization (e.g., colors, labels) do not require re-running simulations. Changes to document text do not require re-generating figures.

This is the Model-View-Controller pattern applied to scientific papers. Simulation is the model, figures are the view, and the Makefile is the controller.

Example: Complete Figure Generation Pipeline

Build a pipeline that runs a BER simulation, saves results to CSV, and generates an IEEE-formatted figure from the data.

Example: Batch Generation of All Paper Figures

Generate all figures for a paper with a single script.

Paper Pipeline Visualizer

See how changes in simulation parameters propagate through the data β†’ figure β†’ document pipeline.

Parameters

Paper Build Process Animation

Watch the sequential build process: simulate, generate tables, generate figures, compile LaTeX.

Parameters

Why This Matters: Reproducible Research in Wireless

IEEE Signal Processing Society now requires authors to submit code alongside papers. A well-structured figure generation pipeline β€” where make paper regenerates the entire paper from raw simulation data β€” satisfies this requirement effortlessly. This is especially critical for wireless system simulations where BER curves with subtle differences can lead to different conclusions.

Key Takeaway

Every figure and table should be generated by a script. Manual figure creation is a reproducibility anti-pattern. Use a Makefile to orchestrate simulation β†’ data β†’ figures β†’ document compilation.

Historical Note: Literate Programming and Reproducibility

1984

Donald Knuth introduced literate programming in 1984, where code and documentation are woven together in a single source. This philosophy influenced Jupyter notebooks, R Markdown, and modern reproducible research practices. The programmatic figure generation advocated here is a direct descendant of Knuth's vision.

Common Mistake: Hardcoded Absolute Paths

Mistake:

Using absolute paths like /home/user/project/figures/ in scripts, which break on any other machine.

Correction:

Use pathlib.Path with relative paths or environment variables:

from pathlib import Path
OUTPUT = Path(__file__).parent / 'figures'

Quick Check

What is the primary benefit of using a Makefile for paper generation?

It makes LaTeX compile faster

It tracks dependencies and only regenerates what changed

It automatically fixes LaTeX errors

It is required by IEEE

Makefile

A build automation file that specifies dependencies between targets and the commands to produce them, ensuring reproducible builds.

Idempotent

A property of a process where running it multiple times produces the same result as running it once.