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_inchesdefaults toNone, not'tight'. This is a deliberate change from matplotlib’s behaviour — see thebbox_inchesparameter description below for the rationale. Users coming from matplotlib who callplt.savefig(..., bbox_inches='tight')out of habit should omit the kwarg (or passbbox_inches='tight'explicitly if they know what they want).- Parameters:
filepath (str) – Output file path. The file extension determines the format if the
formatparameter is not specified.dpi (int, optional) – Dots per inch for rasterized output. If
None, usespp.rcParams["savefig.dpi"](600). Ignored for vector formats (PDF, SVG, EPS).format (str, optional) – File format (e.g.,
'png','pdf','svg','eps'). IfNone, 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 — thepubliplots.subplots()geometry and anypubliplots.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 forside='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 whenbbox_inchesisNone.**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_multipleSave the same figure in multiple formats.
close_allClose all open figures.