Save & Export¶
Thin wrappers around matplotlib.Figure.savefig for common workflows:
export multiple formats in one call, or save-and-display SVGs sized for
notebooks/reports.
Example¶
import dartwork_mpl as dm
# Multi-format export with validation
dm.save_formats(fig, "report/figures/example",
formats=("png", "svg", "pdf"), dpi=300)
# Save and preview
dm.save_and_show(fig, size=720)
# Display an existing SVG
dm.show("output/forecast.svg", size=540)
API¶
- dartwork_mpl.save_formats(fig: Figure, image_stem: str, formats: tuple[str, ...] = ('png', 'pdf'), bbox_inches: str | None = None, validate: bool = True, **kwargs) None[source]¶
Save a figure in multiple specified formats at once.
- Parameters:
fig (matplotlib.figure.Figure) – The Matplotlib figure to save.
image_stem (str) – Base path and filename without extension.
formats (tuple[str, ...], optional) – Tuple of format extensions to save. Default is (“png”, “pdf”).
bbox_inches (str | None, optional) – Bounding box setting for the saved figure. Commonly “tight” to minimize whitespace. Default is None.
validate (bool, optional) – If True, performs visual validation before saving and prints
[VISUAL]warnings to stdout on issues. Default is True.**kwargs – Additional keyword arguments passed to
savefig.
- dartwork_mpl.save_and_show(fig: Figure, image_path: str | None = None, size: int = 600, unit: str = 'pt', **kwargs) None[source]¶
Save a figure to disk, then display it in a Jupyter or web environment.
- Parameters:
fig (matplotlib.figure.Figure) – The Matplotlib figure to save and display.
image_path (str | None, optional) – Path to save the image. If None, a system temporary file is used.
size (int, optional) – Display width. Default is 600.
unit (str, optional) – Unit for the size (‘pt’, ‘px’, etc.). Default is ‘pt’.
**kwargs – Additional keyword arguments passed to
savefig.
- dartwork_mpl.show(image_path: str, size: int = 600, unit: str = 'pt') None[source]¶
Load an SVG image and display it at the specified size in a browser or Jupyter.
- Parameters:
image_path (str) – Path to the SVG image to display.
size (int, optional) – Desired output width. Default is 600.
unit (str, optional) – Unit for the width (‘pt’, ‘px’, etc.). Default is ‘pt’.