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 anAxes(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’srcParams(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"))writesfig1.pdfandfig1.png;save(ax, "fig1.pdf", formats=("png",))writes both as well. A bare stem with noformatswritesDEFAULT_SAVE_FORMAT; a suffix matplotlib does not know ("fig1.v2") is part of the stem, sofig1.v2.pdfresults. Existing files are overwritten, assavefigoverwrites them: an analysis script re-run should replace its figures.- Parameters:
target (
Axes|Figure) – What to save. AnAxessaves its whole figure (every panel).path (
str|PathLike[str]) – Output file, or output stem whenformatsis given.formats (
Sequence[str] |None) – Additional formats to write besidepath’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 passesTrueto keep pyplot’s figure registry small.**savefig_kwargs (
Any) – Forwarded toFigure.savefigunchanged (dpi=,transparent=,bbox_inches=, …).formatis not accepted – the path andformatsdecide it.
- Return type:
- Returns:
listofpathlib.Path– The files written, in the order written: the path’s own format first, thenformatsin 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 (useformats=or a suffix instead). Also aTypeError; no files are written.