calamari.plot.save#

calamari.plot.save(target, path, *, formats=None, close=False, **savefig_kwargs)#

Write a figure to one or more files, from the axes a helper returned.

A thin, deliberate wrapper over Figure.savefig: it resolves the figure from an Axes (so a helper’s return value can be saved directly), writes sibling formats from one stem, creates the output directory, and validates every format before writing anything. It adds nothing to the file – no metadata, no stamp; matplotlib’s own producer fields are left as they are. Publication suitability (vector output, 600 dpi for rasterised parts, TrueType-embedded fonts) comes from the journal style’s rcParams (calamari.style), not from this function, so a figure saved without a style is saved as matplotlib would save it.

The path rule is one sentence: a suffix that names a matplotlib format is a format, and the rest is the stem. save(ax, "fig1.pdf") writes that file; save(ax, "fig1", formats=("pdf", "png")) writes fig1.pdf and fig1.png; save(ax, "fig1.pdf", formats=("png",)) writes both as well. A bare stem with no formats writes DEFAULT_SAVE_FORMAT; a suffix matplotlib does not know ("fig1.v2") is part of the stem, so fig1.v2.pdf results. Existing files are overwritten, as savefig overwrites them: an analysis script re-run should replace its figures.

Parameters:
  • target (Axes | Figure) – What to save. An Axes saves its whole figure (every panel).

  • path (str | PathLike[str]) – Output file, or output stem when formats is given.

  • formats (Sequence[str] | None) – Additional formats to write beside path’s own, each to the same stem. Case-insensitive; a leading dot is tolerated.

  • close (bool) – Close the figure after the last file is written. Off by default so a notebook still shows the figure inline; a script producing many figures passes True to keep pyplot’s figure registry small.

  • **savefig_kwargs (Any) – Forwarded to Figure.savefig unchanged (dpi=, transparent=, bbox_inches=, …). format is not accepted – the path and formats decide it.

Return type:

list[Path]

Returns:

list of pathlib.Path – The files written, in the order written: the path’s own format first, then formats in the order given.

Raises:
  • UnknownFigureFormatError – A requested format is not one the figure’s canvas can write. Raised before any file is written.

  • PlotTypeError – An unsupported target or a format= keyword (use formats= or a suffix instead). Also a TypeError; no files are written.