gsplot.savefig#

savefig(fig, path, *, formats=None, dpi=None, close=False, create_parent=False, overwrite=False, show=True, props=None, **kwargs)#

Save an explicit Figure and optionally display it after all writes.

Parameters:
  • fig (Figure) – The Figure whose native savefig method is used.

  • path (str | PathLike[str]) – A suffix-bearing output path or a suffix-free path combined with formats.

  • formats (str | Sequence[str] | None) – One or more supported formats: png, pdf, or svg.

  • dpi (float | None) – Optional positive output resolution.

  • close (bool) – Explicit lifecycle and filesystem controls. show defaults to True and runs only after every requested write succeeds.

  • create_parent (bool) – Explicit lifecycle and filesystem controls. show defaults to True and runs only after every requested write succeeds.

  • overwrite (bool) – Explicit lifecycle and filesystem controls. show defaults to True and runs only after every requested write succeeds.

  • show (bool) – Explicit lifecycle and filesystem controls. show defaults to True and runs only after every requested write succeeds.

  • props (Mapping[str, Any] | None) – A finite mapping of Matplotlib save properties; gsplot controls may not be supplied through this mapping.

  • **kwargs (Any) – Optional direct Matplotlib save properties (e.g. transparent, facecolor, edgecolor). Direct keyword arguments are merged with and take precedence over props.

Returns:

Absolute paths written in the requested order.

Return type:

tuple[pathlib.Path, ]

Raises:

OutputError – If validation, saving, display, or optional closing fails.

Examples

>>> import gsplot as gs
>>> figure, _ = gs.subplots()
>>> paths = gs.savefig(figure, "figure.png", show=False, overwrite=True)
>>> paths[0].suffix
'.png'
>>> figure.clear()