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.
dpiis passed explicitly rather than left to the rc, so that a figure saved outsideplot_style_context()still comes out atRASTER_DPIinstead of matplotlib’s 100. Left unset it comes fromfitted_raster_dpi(), which isRASTER_DPIfor 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_FORMATrather 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()andfitted_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.