{"id":18847862,"url":"https://github.com/zmoon/savefigs","last_synced_at":"2025-04-14T08:10:24.644Z","repository":{"id":40558937,"uuid":"374693581","full_name":"zmoon/savefigs","owner":"zmoon","description":"Save all open Matplotlib figures","archived":false,"fork":false,"pushed_at":"2025-03-03T20:51:28.000Z","size":99,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T01:39:17.273Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zmoon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-07T14:22:33.000Z","updated_at":"2025-03-03T20:51:29.000Z","dependencies_parsed_at":"2023-12-05T00:26:14.448Z","dependency_job_id":"7b0d54f7-0f97-4de2-954d-3a26d56d497c","html_url":"https://github.com/zmoon/savefigs","commit_stats":{"total_commits":77,"total_committers":2,"mean_commits":38.5,"dds":0.2857142857142857,"last_synced_commit":"c0584fe8c7e005459dbf8dda7711ab5c16edc0e5"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmoon%2Fsavefigs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmoon%2Fsavefigs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmoon%2Fsavefigs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmoon%2Fsavefigs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zmoon","download_url":"https://codeload.github.com/zmoon/savefigs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248843867,"owners_count":21170492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T03:09:53.527Z","updated_at":"2025-04-14T08:10:24.608Z","avatar_url":"https://github.com/zmoon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# savefigs\n\nEasily save all open Matplotlib figures, with useful filenames.\n\n[![CI workflow status](https://github.com/zmoon/savefigs/actions/workflows/ci.yml/badge.svg)](https://github.com/zmoon/savefigs/actions/workflows/ci.yml)\n[![Version on PyPI](https://img.shields.io/pypi/v/savefigs.svg)](https://pypi.org/project/savefigs/)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n\n## Usage\n\n*Assume we have a script `some_script.py` that creates multiple Matplotlib figures.*\n\nImport the `savefigs` function:\n```python\nfrom savefigs import savefigs\n```\n\nThe below examples assume the figures do not have labels (`fig.get_label()`).\nIf a figure does have a label, it will be used in place of `fig{num}`.\n\nDefault save settings (`./{script filename stem}{figure label or fig{num}}.png`):\n```python\nsavefigs()\n# ./some_script_fig1.png, ./some_script_fig2.png, ...\n```\n👆 The filenames tell us which script generated the figures as well as their relative places in the figure generation order (or labels if they are labeled).\n\nSpecify directory:\n```python\nsavefigs(save_dir=\"figs\")  # must exist\n# ./figs/some_script_fig1.png, ./figs/some_script_fig2.png, ...\n```\n\nSpecify a different prefix to the base stem format:\n```python\nsavefigs(stem_prefix=\"run1\")\n# ./run1_fig1.png, ./run1_fig2.png, ...\n```\n\nSave in multiple file formats:\n```python\nsavefigs(formats=[\"png\", \"pdf\"])\n# ./some_script_fig1.png, ./some_script_fig1.pdf, ...\n```\n\nAvoid overwriting files:\n```python\nsavefigs(clobber=False, noclobber_method=\"add_num\")\n# ./some_script_fig3.png (assuming ./some_script_fig{1,2}.png already exist)\n```\n👆 By default (without changing `noclobber_method`), setting `clobber=False` will instead error.\n\n## Background\n\nWhen writing a script that creates multiple figures, I usually label them (usually using the `num` argument to `plt.figure()`/`plt.subplots()`), which makes it easier to find the correct figure window. Then, at the end of the script I write a loop like:\n```python\nfor num in plt.get_fignums():\n    fig = plt.figure(num)\n    fig.savefig(f\"{fig.get_label()}.pdf\", ...)\n    # Maybe another format...\n```\n`savefigs()` essentially does this, but is more robust and provides additional features through keyword arguments. And it saves having to write those lines in the script, instead allowing the simple one-liner:\n```python\nfrom savefigs import savefigs; savefigs()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmoon%2Fsavefigs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzmoon%2Fsavefigs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmoon%2Fsavefigs/lists"}