File I/O¶
Thin wrappers around matplotlib.Figure.savefig for common workflows:
export multiple formats in one call, or save-and-display SVGs sized for
notebooks/reports. They accept the usual savefig keyword arguments; the
custom ones are called out below.
save_formats(fig, image_stem, formats=("svg", "png", "pdf", "eps"), bbox_inches=None, **kwargs)Parameters: -
fig: figure to export. -image_stem: path without extension; parent folders are created. -formats: iterable of formats to write. -bbox_inches: optional value forwarded tosavefig. -**kwargs: any extra arguments passed tosavefig.Returns: -
Noneafter writing one file per requested format.
save_and_show(fig, image_path=None, size=600, unit="pt", **kwargs)Parameters: -
fig: figure to save (closed after saving). -image_path: destination path orNoneto use a temporary SVG. -size: inline display width. -unit: unit forsize(defaults to points). -**kwargs: forwarded tosavefig.Returns: -
None; displays the SVG inline (Jupyter/HTML).
show(image_path, size=600, unit="pt")Parameters: -
image_path: SVG file to display. -size: display width. -unit: unit forsize.Returns: -
None; shows the scaled SVG inline.
Example
fig, ax = plt.subplots()
ax.plot(x, y)
dm.save_formats(fig, "report/figures/example", formats=("png", "svg"), dpi=300)
dm.save_and_show(fig, "report/figures/example.svg", size=520)
- dartwork_mpl.save_formats(fig: Figure, image_stem: str, formats: tuple[str, ...] = ('svg', 'png', 'pdf', 'eps'), bbox_inches: str | None = None, **kwargs) None[source]¶
Save a figure in multiple formats.
- Parameters:
fig (matplotlib.figure.Figure) – Figure to save.
image_stem (str) – Base filename without extension.
formats (tuple, optional) – Tuple of format extensions to save.
bbox_inches (str or Bbox, optional) – Bounding box in inches.
**kwargs – Additional 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 and display it.
- Parameters:
fig (matplotlib.figure.Figure) – Figure to save and display.
image_path (str, optional) – Path to save the image. If None, uses a temporary file.
size (int, optional) – Display size.
unit (str, optional) – Unit for size.
**kwargs – Additional arguments passed to savefig.