根据matplotlib's文档,这应该允许我将多个图打印到PDF文件,每页一个图。
import datetime
import numpy as np
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
# Create the PdfPages object to which we will save the pages:
# The with statement makes sure that the PdfPages object is closed properly at
# the end of the block, even if an Exception occurs.
with PdfPages('multipage_pdf.pdf') as pdf:
plt.figure(figsize=(3, 3))
plt.plot(range(7), [3, 1, 4, 1, 5, 9, 2], 'r-o')
plt.title('Page One')
pdf.savefig() # saves the current figure into a pdf page
plt.close()
# if LaTeX is not installed or error caught, change to `usetex=False`
plt.rc('text', usetex=True)
plt.figure(figsize=(8, 6))
x = np.arange(0, 5, 0.1)
plt.plot(x, np.sin(x), 'b-')
plt.title('Page Two')
pdf.attach_note("plot of sin(x)") # you can add a pdf note to
# attach metadata to a page
pdf.savefig()
plt.close()
但是,当我运行它时,会得到多个FileNotFoundErrors
,如下所示:FileNotFoundError: [WinError 2] The system cannot find the file specified
。
我在做什么错?
我尝试设置usetex=False
,但这并不能解决问题。
完整错误将长达几页,我不确定共享它的最佳方法是什么,但这是它的开始方式: