save_fig

save_fig(fig, dest=None, close=True, **savefig_kw)[source]

Saves a figure and, optionally, closes it.

The way in which the destination path is specified differs from the one used by savefig(). Moreover, if the CWD is in a git repository, attempts to store the commit hash of HEAD in the “Creator” metadata of the file. Supported file formats: ps, eps, pdf, png, svg; (jpeg and tiff via exiftool). Monitoring information is emitted through python’s logging module.

Parameters:
  • fig (Figure) – The figure to be saved.

  • dest (str or path-like or file-like, default the figure label) – The destination file, or file name (path without extension). If a relative path, rcParams['savefig.directory'] (default: '~') is taken as anchor. The file format (extension to append to path) can be specified via savefig_kw['format'] and defaults to rcParams['savefig.format'] (default: 'png').

  • close (bool, default True) – Whether to call matplotlib.pyplot.close() on the figure after saving.

  • **savefig_kw – Keyword arguments for savefig().

Returns:

The destination path, with extension.

Return type:

pathlib.Path