publiplots.savefig

publiplots.savefig(filepath, dpi=None, format=None, bbox_inches=None, transparent=True, facecolor=None, edgecolor=None, pad_inches=0.1, **kwargs)[source]

Save figure with publication-ready defaults.

Thin wrapper around matplotlib.pyplot.savefig() with publiplots’ defaults (transparent background, 600 DPI, bbox_inches=None). Automatically creates parent directories if they don’t exist.

Note

Starting in 0.9.3, bbox_inches defaults to None, not 'tight'. This is a deliberate change from matplotlib’s behaviour — see the bbox_inches parameter description below for the rationale. Users coming from matplotlib who call plt.savefig(..., bbox_inches='tight') out of habit should omit the kwarg (or pass bbox_inches='tight' explicitly if they know what they want).

Parameters:
  • filepath (str) – Output file path. The file extension determines the format if the format parameter is not specified.

  • dpi (int, optional) – Dots per inch for rasterized output. If None, uses pp.rcParams["savefig.dpi"] (600). Ignored for vector formats (PDF, SVG, EPS).

  • format (str, optional) – File format (e.g., 'png', 'pdf', 'svg', 'eps'). If None, inferred from the filepath extension.

  • bbox_inches (str, optional) – Bounding-box setting. None (default, changed in 0.9.3) preserves publiplots’ mm-precise figure layout — the publiplots.subplots() geometry and any publiplots.legend() bands are already measured exactly. Passing 'tight' re-crops the figure to the union of artist bboxes, which shifts figure-anchored legend bands off-canvas for side='top'/'bottom' setups.

  • transparent (bool, default True) – If True, make the background transparent (PNG, PDF, SVG).

  • facecolor (str, optional) – Figure face color. If None, uses the current figure’s facecolor.

  • edgecolor (str, optional) – Figure edge color. If None, uses the current figure’s edgecolor.

  • pad_inches (float, default 0.1) – Padding around the figure when bbox_inches='tight'. Ignored when bbox_inches is None.

  • **kwargs (Any) – Forwarded to matplotlib.pyplot.savefig().

Examples

Save a figure with default settings:

>>> import publiplots as pp
>>> fig, ax = pp.subplots()
>>> pp.scatterplot(data=df, x='x', y='y', ax=ax)
>>> pp.savefig('output.png')

Save with higher DPI:

>>> pp.savefig('output.png', dpi=1200)

Save as PDF (vector format):

>>> pp.savefig('output.pdf')

Save with opaque white background:

>>> pp.savefig('output.png', transparent=False, facecolor='white')

Notes

  • For publications, use DPI >= 600 for rasterized formats (PNG, JPEG).

  • For presentations, DPI = 150 is usually sufficient.

  • For vector formats (PDF, SVG, EPS), DPI is ignored.

  • PDF / SVG are recommended for publications (vector graphics).

See also

save_multiple

Save the same figure in multiple formats.

close_all

Close all open figures.