#!/usr/bin/env python3 """Render a paper figure WITHOUT in-figure title/subtitle/footnote text (that text belongs in the LaTeX caption). Usage: run_bare.py Runs the script unchanged, with two patches: Figure.text becomes a no-op (in these scripts fig.text is used only for the title, subtitle and footnotes; panel titles, axis labels and legends are untouched), and every savefig is redirected to /_bare. with a tight bounding box, so the original outputs are never overwritten.""" import os, runpy, sys import matplotlib matplotlib.use("Agg") from matplotlib.figure import Figure script, out_dir = sys.argv[1], sys.argv[2] orig_save = Figure.savefig Figure.text = lambda self, *a, **k: None def save(self, fname, *a, **k): base, ext = os.path.splitext(os.path.basename(str(fname))) k.update(bbox_inches="tight", pad_inches=0.05) dest = os.path.join(out_dir, f"{base}_bare{ext}") print("wrote", dest) return orig_save(self, dest, *a, **k) Figure.savefig = save sys.argv = [script] runpy.run_path(script, run_name="__main__")