Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

plotting.saving

plotting.saving

Saving matplotlib figures with per-context (poster/talk/paper) presets.

The presets are rcparams.rc_presets entries, not dicts of their own: a context is just “these save.* rcParams, for this call”, which is what rc_context already means.

Attributes

NameDescription
contexts

Functions

NameDescription
save_current_figureSave the current matplotlib figure to a file.
save_figureSave a matplotlib figure to a file.

save_current_figure

plotting.saving.save_current_figure(
    folder,
    filename,
    prepend_date=True,
    **kwargs,
)

Save the current matplotlib figure to a file.

Parameters

NameTypeDescriptionDefault
folderstr or PathThe folder to save the figure in.required
filenamestrThe name of the file to save the figure as (without extension).required
prepend_dateboolWhether to prepend the current date and time to the filename. Defaults to True.True
**kwargsAdditional keyword arguments forwarded to save_figure.{}

save_figure

plotting.saving.save_figure(
    fig,
    folder,
    filename,
    prepend_date=True,
    move_old=True,
    context=None,
    modify_folder_path=True,
    **kwargs,
)

Save a matplotlib figure to a file.

Parameters

NameTypeDescriptionDefault
figmatplotlib.figure.FigureThe figure to save.required
folderstr or PathThe folder to save the figure in.required
filenamestrThe name of the file to save the figure as (without extension).required
prepend_dateboolWhether to prepend the current date and time to the filename. Defaults to True.True
move_oldboolWhether to move old files with the same name to an “old” folder first. Defaults to True.True
context(poster, talk, paper)Named rc_presets bundle of save.* overrides (dpi, transparency, padding) to apply for this call."poster"
modify_folder_pathboolIf True and context is given, append context to folder when it isn’t already the folder’s last component. Defaults to True.True
**kwargsAdditional keyword arguments passed to fig.savefig.{}