mplutils.savefig#
- mplutils.savefig(fname=None, ftype=None, fig=None, **savefig_kwargs)[source]#
Save a
matplotlib.figure.Figureto a file.Wraps
matplotlib.pyplot.savefig().- Parameters:
- fig
matplotlib.figure.Figure, optional If None, use last active figure.
- fname
str, optional File name (and path).
If None, uses the filename of the programs entry point.
If a file name without a file-type extension is provided, uses rcParams[“savefig.format”] unless ftype is provided.
If fname ends in
/or\, it is assumed as a directory in which the output will be saved using the file name of the programs entry point.If
*is in fname, replace it with the file name of the programs entry point.- ftype
stror Sequence[str], optional The file type(s).
If provided, the appropriate extension is appended to fname and the file is saved as that file type.
If a sequence is provided, saves one file for each provided type.
If nothing is provided, infers the file type from fname.
- fig
- Other Parameters:
- **savefig_kwargs
Keyword arguments of
matplotlib.pyplot.savefig().
See also
Examples
Assume a script named
my_plot.pywith the contentsmy_plot.py#import mplutils as mplu import matplotlib.pyplot as plt plt.plot(some_data) mplu.savefig() mplu.savefig(ftype="pdf") mplu.savefig("output/") mplu.savefig("output/*_extra") mplu.savefig("a_plot") mplu.savefig("a_plot", ftype=("pdf", "png")) mplu.savefig("a_plot.pdf", ftype=("pdf", "png"))
Executing
my_plot.pywill save:my_plot.png(assuming plt.rcParams[“savefig.format”] = “png”)my_plot.pdfoutput/my_plot.pngoutput/my_plot_extra.pnga_plot.pnga_plot.pdfanda_plot.pnga_plot.pdf.pdfanda_plot.pdf.png