braincell.vis.save_figure

Contents

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 via figure.write_image (raster) or figure.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. When None the format is inferred from the path suffix.

Returns:

path – The path that was written, for convenient chaining.

Return type:

Path

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.