8000 Add description for metadata argument of savefig · matplotlib/matplotlib@6768d6c · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6768d6c

Browse files
committed
Add description for metadata argument of savefig
1 parent 42f07d9 commit 6768d6c

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,44 @@ def print_raw(self, filename_or_obj, *args, **kwargs):
485485
print_rgba = print_raw
486486

487487
def print_png(self, filename_or_obj, *args, **kwargs):
488+
"""
489+
Write the png data to the given file.
490+
491+
Parameters
492+
----------
493+
filename_or_obj : str or PathLike or file-like object
494+
The file to write to.
495+
496+
metadata : dict, optional
497+
Metadata in the PNG file as key-value pairs of bytes or latin-1
498+
encodable strings.
499+
According to the PNG specification, keys must be shorter than 79
500+
chars.
501+
502+
The PNG specification defines some common keywords that may be
503+
used as appropriate:
504+
- Title: Short (one line) title or caption for image.
505+
- Author: Name of image's creator.
506+
- Description: Description of image (possibly long).
507+
- Copyright: Copyright notice.
508+
- Creation Time: Time of original image creation
509+
(usually RFC 1123 format).
510+
- Software: Software used to create the image.
511+
- Disclaimer: Legal disclaimer.
512+
- Warning: Warning of nature of content.
513+
- Source: Device used to create the image.
514+
- Comment: Miscellaneous comment;
515+
conversion from other image format.
516+
517+
Other keywords may be invented for other purposes.
518+
519+
If 'Software' is not given, an autogenerated value for matplotlib
520+
will be used.
521+
522+
For more details see the PNG specification:
523+
https://www.w3.org/TR/2003/REC-PNG-20031110/#11keywords
524+
525+
"""
488526
FigureCanvasAgg.draw(self)
489527
renderer = self.get_renderer()
490528

lib/matplotlib/figure.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
19791979
savefig(fname, dpi=None, facecolor='w', edgecolor='w',
19801980
orientation='portrait', papertype=None, format=None,
19811981
transparent=False, bbox_inches=None, pad_inches=0.1,
1982-
frameon=None)
1982+
frameon=None, metadata=None)
19831983
19841984
The output formats available depend on the backend being used.
19851985
@@ -2059,6 +2059,16 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
20592059
A list of extra artists that will be considered when the
20602060
tight bbox is calculated.
20612061
2062+
metadata : dict, optional
2063+
Key/value pairs to store in the image metadata. The supported keys
2064+
and defaults depend on the image format and backend:
2065+
2066+
- 'png' with Agg backend: See the parameter ``metadata`` of
2067+
`~.FigureCanvasAgg.print_png`.
2068+
- 'pdf' with pdf backend: See the parameter ``metadata`` of
2069+
`.PdfPages`.
2070+
- 'eps' and 'ps' with PS backend: Only 'Creator' is supported.
2071+
20622072
"""
20632073
kwargs.setdefault('dpi', rcParams['savefig.dpi'])
20642074
if frameon is None:

src/_png.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ const char *Py_write_png__doc__ =
128128
" - Comment: Miscellaneous comment; conversion\n"
129129
" from other image format\n"
130130
"\n"
131+
" For more details see the PNG specification:\n"
132+
" https://www.w3.org/TR/2003/REC-PNG-20031110/#11keywords\n"
133+
"\n"
131134
"Returns\n"
132135
"-------\n"
133136
"buffer : bytes or None\n"

0 commit comments

Comments
 (0)
0