Download run_bare.py from jprivera/final_graphs_paper: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/jprivera/final_graphs_paper/resolve/main/run_bare.py
- Command line
-
hf download hf://jprivera/final_graphs_paper/run_bare.py
-
curl -L -o run_bare.py https://huggingface.co/jprivera/final_graphs_paper/resolve/main/run_bare.py
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__") | |