final_graphs_paper / run_bare.py
jprivera's picture
upload batch 1/1 from pod 38.80.152.76
d2e75be verified
Raw History Blame Contribute Delete
1.11 kB
#!/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 <plot_script.py> <out_dir>
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
<out_dir>/<original name>_bare.<ext> 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__")