MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / PdfPages

Class PdfPages

lib/matplotlib/backends/backend_pgf.py:895–1020  ·  view source on GitHub ↗

A multi-page PDF file using the pgf backend 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.

Source from the content-addressed store, hash-verified

893
894
895class PdfPages:
896 """
897 A multi-page PDF file using the pgf backend
898
899 Examples
900 --------
901 >>> import matplotlib.pyplot as plt
902 >>> # Initialize:
903 >>> with PdfPages('foo.pdf') as pdf:
904 ... # As many times as you like, create a figure fig and save it:
905 ... fig = plt.figure()
906 ... pdf.savefig(fig)
907 ... # When no figure is specified the current figure is saved
908 ... pdf.savefig()
909 """
910
911 def __init__(self, filename, *, metadata=None):
912 """
913 Create a new PdfPages object.
914
915 Parameters
916 ----------
917 filename : str or path-like
918 Plots using `PdfPages.savefig` will be written to a file at this
919 location. Any older file with the same name is overwritten.
920
921 metadata : dict, optional
922 Information dictionary object (see PDF reference section 10.2.1
923 'Document Information Dictionary'), e.g.:
924 ``{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}``.
925
926 The standard keys are 'Title', 'Author', 'Subject', 'Keywords',
927 'Creator', 'Producer', 'CreationDate', 'ModDate', and
928 'Trapped'. Values have been predefined for 'Creator', 'Producer'
929 and 'CreationDate'. They can be removed by setting them to `None`.
930
931 Note that some versions of LaTeX engines may ignore the 'Producer'
932 key and set it to themselves.
933 """
934 self._output_name = filename
935 self._n_figures = 0
936 self._metadata = (metadata or {}).copy()
937 self._info_dict = _create_pdf_info_dict('pgf', self._metadata)
938 self._file = BytesIO()
939
940 def _write_header(self, width_inches, height_inches):
941 pdfinfo = ','.join(
942 _metadata_to_str(k, v) for k, v in self._info_dict.items())
943 latex_header = "\n".join([
944 _DOCUMENTCLASS,
945 r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo,
946 r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
947 % (width_inches, height_inches),
948 r"\usepackage{pgf}",
949 _get_preamble(),
950 r"\setlength{\parindent}{0pt}",
951 r"\begin{document}%",
952 ])

Callers 3

test_pdf_pagesFunction · 0.90

Calls

no outgoing calls

Tested by 3

test_pdf_pagesFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…