A multi-page PDF file. Examples -------- >>> import matplotlib.pyplot as plt >>> # Initialize: >>> with PdfPages('foo.pdf') as pdf: ... # As many times as you like, create a figure fig and save it: ... fig = plt.figure() ... pdf.savefig(fig) ...
| 2599 | |
| 2600 | |
| 2601 | class PdfPages: |
| 2602 | """ |
| 2603 | A multi-page PDF file. |
| 2604 | |
| 2605 | Examples |
| 2606 | -------- |
| 2607 | >>> import matplotlib.pyplot as plt |
| 2608 | >>> # Initialize: |
| 2609 | >>> with PdfPages('foo.pdf') as pdf: |
| 2610 | ... # As many times as you like, create a figure fig and save it: |
| 2611 | ... fig = plt.figure() |
| 2612 | ... pdf.savefig(fig) |
| 2613 | ... # When no figure is specified the current figure is saved |
| 2614 | ... pdf.savefig() |
| 2615 | |
| 2616 | Notes |
| 2617 | ----- |
| 2618 | In reality `PdfPages` is a thin wrapper around `PdfFile`, in order to avoid |
| 2619 | confusion when using `~.pyplot.savefig` and forgetting the format argument. |
| 2620 | """ |
| 2621 | |
| 2622 | @_api.delete_parameter("3.10", "keep_empty", |
| 2623 | addendum="This parameter does nothing.") |
| 2624 | def __init__(self, filename, keep_empty=None, metadata=None): |
| 2625 | """ |
| 2626 | Create a new PdfPages object. |
| 2627 | |
| 2628 | Parameters |
| 2629 | ---------- |
| 2630 | filename : str or path-like or file-like |
| 2631 | Plots using `PdfPages.savefig` will be written to a file at this location. |
| 2632 | The file is opened when a figure is saved for the first time (overwriting |
| 2633 | any older file with the same name). |
| 2634 | |
| 2635 | metadata : dict, optional |
| 2636 | Information dictionary object (see PDF reference section 10.2.1 |
| 2637 | 'Document Information Dictionary'), e.g.: |
| 2638 | ``{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}``. |
| 2639 | |
| 2640 | The standard keys are 'Title', 'Author', 'Subject', 'Keywords', |
| 2641 | 'Creator', 'Producer', 'CreationDate', 'ModDate', and |
| 2642 | 'Trapped'. Values have been predefined for 'Creator', 'Producer' |
| 2643 | and 'CreationDate'. They can be removed by setting them to `None`. |
| 2644 | """ |
| 2645 | self._filename = filename |
| 2646 | self._metadata = metadata |
| 2647 | self._file = None |
| 2648 | |
| 2649 | def __enter__(self): |
| 2650 | return self |
| 2651 | |
| 2652 | def __exit__(self, exc_type, exc_val, exc_tb): |
| 2653 | self.close() |
| 2654 | |
| 2655 | def _ensure_file(self): |
| 2656 | if self._file is None: |
| 2657 | self._file = PdfFile(self._filename, metadata=self._metadata) # init. |
| 2658 | return self._file |
no outgoing calls
searching dependent graphs…