fig_savers
Module Contents
- class fig_savers.FigureSaver(save_under: Optional[pocketutils.core.PathLike] = None, *, clear: Union[bool, Callable[[matplotlib.figure.Figure], Any]] = False, as_type: Optional[str] = None, check_paths: bool = True, sanitize_paths: bool = True, log: Optional[Callable[[str], None]] = None, kwargs: Mapping[str, Any] = None)
Offers some small, specific extensions over matplotlib’s
figure.savefig.- Specifically::
can remove the figure from memory each iteration
creates directories as needed
can save a multi-figure PDF
complains about issues
can auto-fix some
the
FigureSaver.savefunction handles iterators of different types
See
save()for more info.Constructor.
- Parameters
save_under – A parent directory assumed for all saved figures
clear – Auto-close each figure after saving (if a callable, call it)
as_type – Force a specific filename suffix (e.g.
as_type=".jpg")check_paths – Check that paths are valid; without
sanitize_paths, raises an error if a path is invalid; seepocketutils.tools.path_tools.PathTools.sanitize_path()sanitize_paths – Try to sanitize paths (implies
check_paths)log – Call this function with a message indicating that a sanitized path differs
kwargs – Passed to
savefig
- save(figure: FigureSeqLike, path: pocketutils.core.PathLike = '', names: Optional[Iterator[str]] = None, *, overwrite: bool = True, use_labels: bool = False) None
- Saves either:
a single figure
figureto pathpatha bunch of figures to directory
pathiffigureis an iterable (list, dict, etc) over figuresa single PDF with multiple figures, if
pathends in.pdf
- If
figureis iterable (case 2), it can be either: an iterable over Figures
an iterable over (name, Figure) pairs, where
nameprovides the filename (under the directorypath)
If it’s the first case and
namesis set, will use those to provide the filenames. Otherwise, falls back to numbering them (ex:directory/1.png, etc).If
use_labelsis set, tries to use eachFigure.get_label().Note
Figure labels are not typically set by default; you should call
Figure.set_label()when usinguse_labels.
- save_all_as_pdf(figures: FigureSeqLike, path: pocketutils.core.PathLike, names: Optional[Iterator[str]] = None, *, overwrite: bool = True, metadata: Optional[Mapping[str, str]] = None) None
Save a single PDF with potentially many figures. See
save()for more info.
- save_all(figures: FigureSeqLike, directory: pocketutils.core.PathLike = '.', names: Optional[Iterator[str]] = None, *, use_labels: bool = False, overwrite: bool = True) None
Saves potentially multiple figures into a directory.
See
save()for more info.
- save_one(figure: matplotlib.figure.Figure, path: pocketutils.core.PathLike, overwrite: bool) None
Saves one figure to a specific path. This is pretty similar to
Figure.savefig.