Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ece71a0

Browse files
committed
Document behavior of savefig("extensionless-name").
When the filename has no extension *and* the `format` kwarg is unset, the suffix derived from the savefig.format rcparam is appended to the filename. (I'm not sure the behavior is really that nice, but that's what it is right now; this is just documenting it.)
1 parent a00fdf1 commit ece71a0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/matplotlib/figure.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,12 +2044,16 @@ def savefig(self, fname, *, transparent=None, **kwargs):
20442044
possibly some backend-dependent object such as
20452045
`matplotlib.backends.backend_pdf.PdfPages`.
20462046
2047-
If *format* is not set, then the output format is inferred from
2048-
the extension of *fname*, if any, and from :rc:`savefig.format`
2049-
otherwise. If *format* is set, it determines the output format.
2050-
2051-
Hence, if *fname* is not a path or has no extension, remember to
2052-
specify *format* to ensure that the correct backend is used.
2047+
If *format* is set, it determines the output format, and the file
2048+
is saved as *fname*. Note that *fname* is used verbatim, and there
2049+
is no attempt to make the extension, if any, of *fname* match
2050+
*format*, and no extension is appended.
2051+
2052+
If *format* is not set, then the format is inferred from the
2053+
extension of *fname*, if there is one. If *format* is not
2054+
set and *fname* has no extension, then the file is saved with
2055+
:rc:`savefig.format` and the appropriate extension is appended to
2056+
*fname*.
20532057
20542058
Other Parameters
20552059
----------------

0 commit comments

Comments
 (0)