atompy.savefig#

atompy.savefig(fname=None, ftype=None, fig=None, **savefig_kwargs)[source]#

Save a matplotlib.figure.Figure to a file.

Wraps matplotlib.pyplot.savefig().

Parameters:
figmatplotlib.figure.Figure, optional

If None, use last active figure.

fnamestr, 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.

ftypestr or 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.

Other Parameters:
**savefig_kwargs

Keyword arguments of matplotlib.pyplot.savefig().

Examples

Assume a script named my_plot.py with the contents

my_plot.py#
import atompy as ap

plt.plot(some_data)

ap.savefig()
ap.savefig(ftype="pdf")
ap.savefig("output/")
ap.savefig("output/*_extra")
ap.savefig("a_plot")
ap.savefig("a_plot", ftype=("pdf", "png"))
ap.savefig("a_plot.pdf", ftype=("pdf", "png"))

Executing my_plot.py will save:

  • my_plot.png (assuming plt.rcParams[“savefig.format”] = “png”)

  • my_plot.pdf

  • output/my_plot.png

  • output/my_plot_extra.png

  • a_plot.pdf

  • a_plot.pdf and a_plot.png

  • a_plot.pdf.pdf and a_plot.pdf.png