@@ -2249,29 +2249,41 @@ class PdfPages(object):
2249
2249
"""
2250
2250
A multi-page PDF file.
2251
2251
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.
2265
2270
"""
2266
2271
__slots__ = ('_file' , 'keep_empty' )
2267
2272
2268
2273
def __init__ (self , filename , keep_empty = True ):
2269
2274
"""
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.
2275
2287
"""
2276
2288
self ._file = PdfFile (filename )
2277
2289
self .keep_empty = keep_empty
@@ -2302,10 +2314,19 @@ def infodict(self):
2302
2314
2303
2315
def savefig (self , figure = None , ** kwargs ):
2304
2316
"""
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.
2309
2330
"""
2310
2331
if isinstance (figure , Figure ):
2311
2332
figure .savefig (self , format = 'pdf' , ** kwargs )
0 commit comments