Exporting plots
The dynlib.plot.export helper wraps the Matplotlib savefig/show workflow so your scripts keep the same consistent defaults regardless of whether you draw a single panel, grid layout, or higher-level container.
Core functions
export.savefig(fig_or_ax, path, *, fmts=("png",), dpi=300, transparent=False, pad=0.01, metadata=None, bbox_inches="tight")
fig_or_axaccepts a figure, axes, or any dynlib layout object (fig.grid,AxesGrid, etc.). The helper finds the underlying figure automatically so you can call it right after plotting without grabbingfig.figure.pathcan either include an extension (e.g.,"plots/phase.png") or omit it (e.g.,"plots/phase"). When you pass an extension, the helper writes only that format; omit the extension and specifyfmtsto save multiple formats in one go.fmtsdefaults to("png",)unless you inferred formats from the path. The helper normalizes, deduplicates, and lowercases the values you provide so you can pass(".PNG", ".pdf")without extra parsing.- The remaining keyword arguments mirror Matplotlib's
savefig. Usedpifor resolution,transparentfor alpha backgrounds,padto add whitespace, andmetadatato embed search-friendly tags. When you rely on dynlib'sfighelpers withconstrained_layout=True, the helper automatically avoids applying a tight bounding box that could clip decorations.
export.show()
Call export.show() at the end of a script, notebook cell, or in any interactive session to trigger Matplotlib's plt.show(). It follows dynlib's styling, so figure numbering and layouts behave the same way whether you use the CLI or import the helpers in a script.
Best practices
- Keep
exportimports next to your plotting helpers:from dynlib.plot import fig, series, export. That way you can consistently callexport.show()after every figure set. - When saving multiple formats, leave the extension off
pathand rely onfmts. For example,export.savefig(ax, "figures/lorenz", fmts=("svg","png"))writeslorenz.svgandlorenz.pngwith the same dpi/pad settings. - Pass dynlib containers like
axes = fig.grid(...)or the return value of helpers such asplot.vectorfield()directly tosavefig;exporttraverses the container to locate the figure automatically. - Use
metadata(a dict of string keys/values) for searchable keywords or author info when generating publication-ready images.
For a worked example and more formatting notes, return to the Plotting basics guide or explore the rest of the plotting docs.