braincell.vis.save_figure#
- braincell.vis.save_figure(figure, path, *, dpi=None, transparent=False, format=None)[source]#
Save a vis backend return value to disk.
- Parameters:
figure (
Any) –Return value from
plot2d(),plot3d(), or a raw matplotlib / PyVista / Plotly handle. The specific types recognised are:matplotlib.axes.Axes— the owning figure is saved.matplotlib.figure.Figure— saved directly.pyvista.Plotter— screenshot for raster formats, VTK / HTML export for vector formats.plotly.graph_objects.Figure— written viafigure.write_image(raster) orfigure.write_html.
path (
str|PathLike) – Destination. Missing parent directories are not created implicitly — the caller owns filesystem layout.dpi (
int|None) – DPI hint forwarded to matplotlib and PyVista. Plotly ignores it (use width/height on the figure instead).transparent (
bool) – Whether to request a transparent background. Matplotlib honours this directly. PyVista uses its off-screen transparent path. Plotly is ignored.format (
str|None) – Explicit format override. WhenNonethe format is inferred from the path suffix.
- Returns:
path – The path that was written, for convenient chaining.
- Return type:
- Raises:
TypeError – If the figure type is not recognised.
ValueError – If a vector path is requested for a backend that cannot serve it (e.g. PyVista for
.pdf).
Notes
The dispatch is intentionally conservative — it only recognises types it can handle natively. Pass
figure.savefig(...)(for matplotlib) or the backend-specific API directly when you need finer control.