GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Installation
  • Documentation
  • Examples
  • Tutorials
  • Contributing

This view

  • Original page
  • New address

GeezerVison is showing matplotlib.org — matplotlib.pyplot.savefig — Matplotlib 3.1.2 documentation

You are reading an old version of the documentation (v3.1.1). For the latest version see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html
Version 3.1.2
matplotlib
Fork me on GitHub

Navigation

  • index
  • modules |
  • next |
  • previous |
  • home| 
  • contents »
  • API Overview »
  • matplotlib.pyplot »
  • matplotlib.pyplot »

Quick search

Table of Contents

  • matplotlib.pyplot.savefig
    • Examples using matplotlib.pyplot.savefig

Related Topics

  • Documentation overview
    • API Overview
      • matplotlib.pyplot
        • matplotlib.pyplot
          • Previous: matplotlib.pyplot.rgrids
          • Next: matplotlib.pyplot.sca
Show Page Source

matplotlib.pyplot.savefig¶

matplotlib.pyplot.savefig(*args, **kwargs)[source]¶

Save the current figure.

Call signature:

savefig(fname, dpi=None, facecolor='w', edgecolor='w',
        orientation='portrait', papertype=None, format=None,
        transparent=False, bbox_inches=None, pad_inches=0.1,
        frameon=None, metadata=None)

The output formats available depend on the backend being used.

Parameters:
fname : str or PathLike or file-like object

A path, or a Python file-like object, or possibly some backend-dependent object such as matplotlib.backends.backend_pdf.PdfPages.

If format is not set, then the output format is inferred from the extension of fname, if any, and from rcParams["savefig.format"] = 'png' otherwise. If format is set, it determines the output format.

Hence, if fname is not a path or has no extension, remember to specify format to ensure that the correct backend is used.

Other Parameters:
dpi : [ None | scalar > 0 | 'figure' ]

The resolution in dots per inch. If None, defaults to rcParams["savefig.dpi"] = 'figure'. If 'figure', uses the figure's dpi value.

quality : [ None | 1 <= scalar <= 100 ]

The image quality, on a scale from 1 (worst) to 95 (best). Applicable only if format is jpg or jpeg, ignored otherwise. If None, defaults to rcParams["savefig.jpeg_quality"] = 95 (95 by default). Values above 95 should be avoided; 100 completely disables the JPEG quantization stage.

optimize : bool

If True, indicates that the JPEG encoder should make an extra pass over the image in order to select optimal encoder settings. Applicable only if format is jpg or jpeg, ignored otherwise. Is False by default.

progressive : bool

If True, indicates that this image should be stored as a progressive JPEG file. Applicable only if format is jpg or jpeg, ignored otherwise. Is False by default.

facecolor : color spec or None, optional

The facecolor of the figure; if None, defaults to rcParams["savefig.facecolor"] = 'white'.

edgecolor : color spec or None, optional

The edgecolor of the figure; if None, defaults to rcParams["savefig.edgecolor"] = 'white'

orientation : {'landscape', 'portrait'}

Currently only supported by the postscript backend.

papertype : str

One of 'letter', 'legal', 'executive', 'ledger', 'a0' through 'a10', 'b0' through 'b10'. Only supported for postscript output.

format : str

The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when this is unset is documented under fname.

transparent : bool

If True, the axes patches will all be transparent; the figure patch will also be transparent unless facecolor and/or edgecolor are specified via kwargs. This is useful, for example, for displaying a plot on top of a colored background on a web page. The transparency of these patches will be restored to their original values upon exit of this function.

bbox_inches : str or Bbox, optional

Bbox in inches. Only the given portion of the figure is saved. If 'tight', try to figure out the tight bbox of the figure. If None, use savefig.bbox

pad_inches : scalar, optional

Amount of padding around the figure when bbox_inches is 'tight'. If None, use savefig.pad_inches

bbox_extra_artists : list of Artist, optional

A list of extra artists that will be considered when the tight bbox is calculated.

metadata : dict, optional

Key/value pairs to store in the image metadata. The supported keys and defaults depend on the image format and backend:

  • 'png' with Agg backend: See the parameter metadata of print_png.
  • 'pdf' with pdf backend: See the parameter metadata of PdfPages.
  • 'eps' and 'ps' with PS backend: Only 'Creator' is supported.
pil_kwargs : dict, optional

Additional keyword arguments that are passed to PIL.Image.save when saving the figure. Only applicable for formats that are saved using Pillow, i.e. JPEG, TIFF, and (if the keyword is set to a non-None value) PNG.

Examples using matplotlib.pyplot.savefig¶

../../_images/sphx_glr_usetex_fonteffects_thumb.png

Usetex Fonteffects

../../_images/sphx_glr_print_stdout_sgskip_thumb.png

Print Stdout

../../_images/sphx_glr_rasterization_demo_thumb.png

Rasterization Demo

../../_images/sphx_glr_svg_filter_line_thumb.png

SVG Filter Line

../../_images/sphx_glr_svg_filter_pie_thumb.png

SVG Filter Pie

../../_images/sphx_glr_svg_histogram_sgskip_thumb.png

SVG Histogram

../../_images/sphx_glr_svg_tooltip_sgskip_thumb.png

SVG Tooltip

../../_images/sphx_glr_pgf_fonts_thumb.png

Pgf Fonts

../../_images/sphx_glr_pgf_preamble_sgskip_thumb.png

Pgf Preamble

../../_images/sphx_glr_pgf_texsystem_thumb.png

Pgf Texsystem

© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2018 The Matplotlib development team.
Last updated on Jan 05, 2020. Created using Sphinx 1.8.5. Doc version v3.1.1-79-g90d53b526.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.