當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python matplotlib PdfPages用法及代碼示例

本文簡要介紹 python 語言中 matplotlib.backends.backend_pgf.PdfPages 的用法。

用法

class matplotlib.backends.backend_pgf.PdfPages(filename, *, keep_empty=<object object>, metadata=None)

基礎: object

使用 pgf 後端的多頁 PDF 文件

例子

>>> 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)
...     # When no figure is specified the current figure is saved
...     pdf.savefig()

創建一個新的PdfPages 對象。

參數
filename str 或 path-like

使用 PdfPages.savefig 的繪圖將被寫入此位置的文件中。任何同名的舊文件都會被覆蓋。

keep_empty 布爾值,默認值:真

如果設置為 False,則在關閉時將自動刪除空的 pdf 文件。

metadata 字典,可選

信息字典對象(參見 PDF 參考第 10.2.1 節“文檔信息字典”),例如:{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}.

標準 key 是'Title'、'Author'、'Subject'、'Keywords'、'Creator'、'Producer'、'CreationDate'、'ModDate'和'Trapped'。已為 'Creator'、'Producer' 和 'CreationDate' 預定義值。可以通過將它們設置為 None 來刪除它們。

請注意,LaTeX 引擎的某些版本可能會忽略 'Producer' 鍵並將其設置為自己。

相關用法


注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.backends.backend_pgf.PdfPages。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。