save_figure

ell1fit.plotting.save_figure(fig, path, fmt=None, dpi=None, **kwargs)[source]

Write a figure and close it.

Closing here rather than at the call site is not tidiness: two of the corner-plot writers used to leak a figure per call, and one of them fires every thousand sampler iterations.

dpi is passed explicitly rather than left to the rc, so that a figure saved outside plot_style_context() still comes out at RASTER_DPI instead of matplotlib’s 100. Left unset it comes from fitted_raster_dpi(), which is RASTER_DPI for every figure of a size somebody chose and lower only for one that outgrew the ceiling. It is not ignored by the vector formats: a rasterized element inside a PDF is rendered at this resolution too.

A figure large enough to exhaust memory while being written falls back to LARGE_FIGURE_FORMAT rather than taking the run down with it. A whole fit used to be lost at the last step, after the sampling was over and the chain was safely on disk, because the final corner plot could not be drawn. corner_plot_kwargs() and fitted_raster_dpi() are meant to keep that from arising; this is the net underneath them, for the figure nobody predicted.

Parameters:
figmatplotlib.figure.Figure

The figure to write.

pathstr

Output root or complete file name; see figure_path().

fmtstr or None

Format for a bare root.

dpifloat or None

Resolution for raster formats. Defaults to RASTER_DPI.

Returns:
str

The path written – which is not always the path asked for, if the fallback above fired. Callers log it rather than reconstructing it.