python - 在 Python 中将多个图打印到 PDF(每页一个图)
问题描述
从matplotlib 的文档中,这应该允许我将多个图打印到 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
,但这并不能解决它。
完整的错误将长达几页,我不确定分享它的最佳方式是什么,但它是这样开始的:
解决方案
推荐阅读
- php - 这个 php / mysql 在 localhost 和远程服务器上的行为有什么不同吗?
- react-native - 按钮未定位在 React Native 中
- r - 使用ggrepel使用换行符时如何左对齐?
- python - 如何将图像保存到新目录?
- python - 如何将多个数组属性值获取到 csv 文件中
- python - Spark高效的groupby操作-重新分区?
- javascript - 单击侧边栏时未调用 onClick
- r - 如何将每日流量数据重新排列为每月格式并使用 R 对每个月的流量值进行排名
- linux - xkb 是 xlib 标准的一部分吗?
- java - java.time.DateTimeException:基于区域的 ZoneId 的 ID 无效,格式无效:Java