Skip to content

Commit d043977

Browse files
committed
DOC: update Figure.savefig signature and re-order docstring
1 parent 6c2d146 commit d043977

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

lib/matplotlib/figure.py

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,10 +2837,11 @@ def savefig(self, fname, *, transparent=None, **kwargs):
28372837
28382838
Call signature::
28392839
2840-
savefig(fname, dpi=None, facecolor='w', edgecolor='w',
2841-
orientation='portrait', papertype=None, format=None,
2842-
transparent=False, bbox_inches=None, pad_inches=0.1,
2843-
frameon=None, metadata=None)
2840+
savefig(fname, *, dpi='figure', format=None, metadata=None,
2841+
bbox_inches=None, pad_inches=0.1,
2842+
facecolor='auto', edgecolor='auto',
2843+
backend=None, **kwargs
2844+
)
28442845
28452846
The available output formats depend on the backend being used.
28462847
@@ -2868,6 +2869,29 @@ def savefig(self, fname, *, transparent=None, **kwargs):
28682869
The resolution in dots per inch. If 'figure', use the figure's
28692870
dpi value.
28702871
2872+
format : str
2873+
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when
2874+
this is unset is documented under *fname*.
2875+
2876+
metadata : dict, optional
2877+
Key/value pairs to store in the image metadata. The supported keys
2878+
and defaults depend on the image format and backend:
2879+
2880+
- 'png' with Agg backend: See the parameter ``metadata`` of
2881+
`~.FigureCanvasAgg.print_png`.
2882+
- 'pdf' with pdf backend: See the parameter ``metadata`` of
2883+
`~.backend_pdf.PdfPages`.
2884+
- 'svg' with svg backend: See the parameter ``metadata`` of
2885+
`~.FigureCanvasSVG.print_svg`.
2886+
- 'eps' and 'ps' with PS backend: Only 'Creator' is supported.
2887+
2888+
bbox_inches : str or `.Bbox`, default: :rc:`savefig.bbox`
2889+
Bounding box in inches: only the given portion of the figure is
2890+
saved. If 'tight', try to figure out the tight bbox of the figure.
2891+
2892+
pad_inches : float, default: :rc:`savefig.pad_inches`
2893+
Amount of padding around the figure when bbox_inches is 'tight'.
2894+
28712895
facecolor : color or 'auto', default: :rc:`savefig.facecolor`
28722896
The facecolor of the figure. If 'auto', use the current figure
28732897
facecolor.
@@ -2876,6 +2900,14 @@ def savefig(self, fname, *, transparent=None, **kwargs):
28762900
The edgecolor of the figure. If 'auto', use the current figure
28772901
edgecolor.
28782902
2903+
backend : str, optional
2904+
Use a non-default backend to render the file, e.g. to render a
2905+
png file with the "cairo" backend rather than the default "agg",
2906+
or a pdf file with the "pgf" backend rather than the default
2907+
"pdf". Note that the default backend is normally sufficient. See
2908+
:ref:`the-builtin-backends` for a list of valid backends for each
2909+
file format. Custom backends can be referenced as "module://...".
2910+
28792911
orientation : {'landscape', 'portrait'}
28802912
Currently only supported by the postscript backend.
28812913
@@ -2884,57 +2916,30 @@ def savefig(self, fname, *, transparent=None, **kwargs):
28842916
'a10', 'b0' through 'b10'. Only supported for postscript
28852917
output.
28862918
2887-
format : str
2888-
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when
2889-
this is unset is documented under *fname*.
2890-
28912919
transparent : bool
28922920
If *True*, the Axes patches will all be transparent; the
2893-
Figure patch will also be transparent unless facecolor
2894-
and/or edgecolor are specified via kwargs.
2921+
Figure patch will also be transparent unless *facecolor*
2922+
and/or *edgecolor* are specified via kwargs.
28952923
2896-
If *False* has no effect and leaves the color of the Axes and
2897-
Figure patches as they are.
2924+
If *False* has no effect and the color of the Axes and
2925+
Figure patches are unchanged (unless the Figure patch
2926+
is specified via the *facecolor* and/or *edgecolor* keyword
2927+
arguments in which case those colors are used).
28982928
2899-
This is useful, for example, for displaying
2900-
a plot on top of a colored background on a web page. The
2901-
transparency of these patches will be restored to their
2929+
The transparency of these patches will be restored to their
29022930
original values upon exit of this function.
29032931
2904-
bbox_inches : str or `.Bbox`, default: :rc:`savefig.bbox`
2905-
Bounding box in inches: only the given portion of the figure is
2906-
saved. If 'tight', try to figure out the tight bbox of the figure.
2907-
2908-
pad_inches : float, default: :rc:`savefig.pad_inches`
2909-
Amount of padding around the figure when bbox_inches is 'tight'.
2932+
This is useful, for example, for displaying
2933+
a plot on top of a colored background on a web page.
29102934
29112935
bbox_extra_artists : list of `~matplotlib.artist.Artist`, optional
29122936
A list of extra artists that will be considered when the
29132937
tight bbox is calculated.
29142938
2915-
backend : str, optional
2916-
Use a non-default backend to render the file, e.g. to render a
2917-
png file with the "cairo" backend rather than the default "agg",
2918-
or a pdf file with the "pgf" backend rather than the default
2919-
"pdf". Note that the default backend is normally sufficient. See
2920-
:ref:`the-builtin-backends` for a list of valid backends for each
2921-
file format. Custom backends can be referenced as "module://...".
2922-
2923-
metadata : dict, optional
2924-
Key/value pairs to store in the image metadata. The supported keys
2925-
and defaults depend on the image format and backend:
2926-
2927-
- 'png' with Agg backend: See the parameter ``metadata`` of
2928-
`~.FigureCanvasAgg.print_png`.
2929-
- 'pdf' with pdf backend: See the parameter ``metadata`` of
2930-
`~.backend_pdf.PdfPages`.
2931-
- 'svg' with svg backend: See the parameter ``metadata`` of
2932-
`~.FigureCanvasSVG.print_svg`.
2933-
- 'eps' and 'ps' with PS backend: Only 'Creator' is supported.
2934-
29352939
pil_kwargs : dict, optional
29362940
Additional keyword arguments that are passed to
29372941
`PIL.Image.Image.save` when saving the figure.
2942+
29382943
"""
29392944

29402945
kwargs.setdefault('dpi', mpl.rcParams['savefig.dpi'])

0 commit comments

Comments
 (0)