8000 refactor docstrings of PdfPages · matplotlib/matplotlib@cb805ad · GitHub
[go: up one dir, main page]

Skip to content

Commit cb805ad

Browse files
committed
refactor docstrings of PdfPages
1 parent dffaf4e commit cb805ad

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,29 +2249,41 @@ class PdfPages(object):
22492249
"""
22502250
A multi-page PDF file.
22512251
2252-
Use like this::
2253-
2254-
# Initialize:
2255-
with PdfPages('foo.pdf') as pdf:
2256-
2257-
# As many times as you like, create a figure fig and save it:
2258-
# When no figure is specified the current figure is saved
2259-
pdf.savefig(fig)
2260-
pdf.savefig()
2261-
2262-
(In reality PdfPages is a thin wrapper around PdfFile, in order to
2263-
avoid confusion when using savefig and forgetting the format
2264-
argument.)
2252+
Examples
2253+
--------
2254+
2255+
>>> import matplotlib.pyplot as plt
2256+
>>> # Initialize:
2257+
>>> with PdfPages('foo.pdf') as pdf:
2258+
... # As many times as you like, create a figure fig and save it:
2259+
... fig = plt.figure()
2260+
... pdf.savefig(fig)
2261+
... # When no figure is specified the current figure is saved
2262+
... pdf.savefig()
2263+
2264+
Notes
2265+
-----
2266+
2267+
In reality :class:`PdfPages` is a thin wrapper around :class:`PdfFile`, in
2268+
order to avoid confusion when using :func:`~matplotlib.pyplot.savefig` and
2269+
forgetting the format argument.
22652270
"""
22662271
__slots__ = ('_file', 'keep_empty')
22672272

22682273
def __init__(self, filename, keep_empty=True):
22692274
"""
2270-
Create a new PdfPages object that will be written to the file
2271-
named *filename*. The file is opened at once and any older
2272-
file with the same name is overwritten.
2273-
If keep_empty is set to False then empty pdf files will be deleted when
2274-
closed.
2275+
Create a new PdfPages object.
2276+
2277+
Parameters
2278+
----------
2279+
2280+
filename: str
2281+
Plots using :meth:`PdfPages.savefig` will be written to a file at
2282+
this location. The file is opened at once and any older file with
2283+
the same name is overwritten.
2284+
keep_empty: bool, optional
2285+
If set to False, then empty pdf files will be deleted automatically
2286+
when closed.
22752287
"""
22762288
self._file = PdfFile(filename)
22772289
self.keep_empty = keep_empty
@@ -2302,10 +2314,19 @@ def infodict(self):
23022314

23032315
def savefig(self, figure=None, **kwargs):
23042316
"""
2305-
Save the Figure instance *figure* to this file as a new page.
2306-
If *figure* is a number, the figure instance is looked up by
2307-
number, and if *figure* is None, the active figure is saved.
2308-
Any other keyword arguments are passed to Figure.savefig.
2317+
Saves a :class:`~matplotlib.figure.Figure` to this file as a new page.
2318+
2319+
Any other keyword arguments are passed to
2320+
:meth:`~matplotlib.figure.Figure.savefig`.
2321+
2322+
Parameters
2323+
----------
2324+
2325+
figure: :class:`~matplotlib.figure.Figure` or int, optional
2326+
Specifies what figure is saved to file. If not specified, the
2327+
active figure is saved. If a :class:`~matplotlib.figure.Figure`
2328+
instance is provided, this figure is saved. If an int is specified,
2329+
the figure instance to save is looked up by number.
23092330
"""
23102331
if isinstance(figure, Figure):
23112332
figure.savefig(self, format='pdf', **kwargs)

0 commit comments

Comments
 (0)
0