Skip to content

Commit c5d7ce2

Browse files
authored
Merge pull request #20221 from tacaswell/doc_savefig_transparent
DOC: clarify that savefig(..., transparent=False) has no effect
2 parents cfc6b1f + d043977 commit c5d7ce2

File tree

1 file changed

+48
-39
lines changed

1 file changed

+48
-39
lines changed

lib/matplotlib/figure.py

+48-39
Original file line numberDiff line numberDiff line change
@@ -2841,10 +2841,11 @@ def savefig(self, fname, *, transparent=None, **kwargs):
28412841
28422842
Call signature::
28432843
2844-
savefig(fname, dpi=None, facecolor='w', edgecolor='w',
2845-
orientation='portrait', papertype=None, format=None,
2846-
transparent=False, bbox_inches=None, pad_inches=0.1,
2847-
frameon=None, metadata=None)
2844+
savefig(fname, *, dpi='figure', format=None, metadata=None,
2845+
bbox_inches=None, pad_inches=0.1,
2846+
facecolor='auto', edgecolor='auto',
2847+
backend=None, **kwargs
2848+
)
28482849
28492850
The available output formats depend on the backend being used.
28502851
@@ -2872,6 +2873,29 @@ def savefig(self, fname, *, transparent=None, **kwargs):
28722873
The resolution in dots per inch. If 'figure', use the figure's
28732874
dpi value.
28742875
2876+
format : str
2877+
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when
2878+
this is unset is documented under *fname*.
2879+
2880+
metadata : dict, optional
2881+
Key/value pairs to store in the image metadata. The supported keys
2882+
and defaults depend on the image format and backend:
2883+
2884+
- 'png' with Agg backend: See the parameter ``metadata`` of
2885+
`~.FigureCanvasAgg.print_png`.
2886+
- 'pdf' with pdf backend: See the parameter ``metadata`` of
2887+
`~.backend_pdf.PdfPages`.
2888+
- 'svg' with svg backend: See the parameter ``metadata`` of
2889+
`~.FigureCanvasSVG.print_svg`.
2890+
- 'eps' and 'ps' with PS backend: Only 'Creator' is supported.
2891+
2892+
bbox_inches : str or `.Bbox`, default: :rc:`savefig.bbox`
2893+
Bounding box in inches: only the given portion of the figure is
2894+
saved. If 'tight', try to figure out the tight bbox of the figure.
2895+
2896+
pad_inches : float, default: :rc:`savefig.pad_inches`
2897+
Amount of padding around the figure when bbox_inches is 'tight'.
2898+
28752899
facecolor : color or 'auto', default: :rc:`savefig.facecolor`
28762900
The facecolor of the figure. If 'auto', use the current figure
28772901
facecolor.
@@ -2880,6 +2904,14 @@ def savefig(self, fname, *, transparent=None, **kwargs):
28802904
The edgecolor of the figure. If 'auto', use the current figure
28812905
edgecolor.
28822906
2907+
backend : str, optional
2908+
Use a non-default backend to render the file, e.g. to render a
2909+
png file with the "cairo" backend rather than the default "agg",
2910+
or a pdf file with the "pgf" backend rather than the default
2911+
"pdf". Note that the default backend is normally sufficient. See
2912+
:ref:`the-builtin-backends` for a list of valid backends for each
2913+
file format. Custom backends can be referenced as "module://...".
2914+
28832915
orientation : {'landscape', 'portrait'}
28842916
Currently only supported by the postscript backend.
28852917
@@ -2888,53 +2920,30 @@ def savefig(self, fname, *, transparent=None, **kwargs):
28882920
'a10', 'b0' through 'b10'. Only supported for postscript
28892921
output.
28902922
2891-
format : str
2892-
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when
2893-
this is unset is documented under *fname*.
2894-
28952923
transparent : bool
28962924
If *True*, the Axes patches will all be transparent; the
2897-
figure patch will also be transparent unless facecolor
2898-
and/or edgecolor are specified via kwargs.
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
2902-
original values upon exit of this function.
2925+
Figure patch will also be transparent unless *facecolor*
2926+
and/or *edgecolor* are specified via kwargs.
29032927
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.
2928+
If *False* has no effect and the color of the Axes and
2929+
Figure patches are unchanged (unless the Figure patch
2930+
is specified via the *facecolor* and/or *edgecolor* keyword
2931+
arguments in which case those colors are used).
29072932
2908-
pad_inches : float, default: :rc:`savefig.pad_inches`
2909-
Amount of padding around the figure when bbox_inches is 'tight'.
2933+
The transparency of these patches will be restored to their
2934+
original values upon exit of this function.
2935+
2936+
This is useful, for example, for displaying
2937+
a plot on top of a colored background on a web page.
29102938
29112939
bbox_extra_artists : list of `~matplotlib.artist.Artist`, optional
29122940
A list of extra artists that will be considered when the
29132941
tight bbox is calculated.
29142942
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-
29352943
pil_kwargs : dict, optional
29362944
Additional keyword arguments that are passed to
29372945
`PIL.Image.Image.save` when saving the figure.
2946+
29382947
"""
29392948

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

0 commit comments

Comments
 (0)