python - 在matplotlib中创建多页PDF而不在桌面上绘制图形
问题描述
在以下示例代码中...
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
with PdfPages('multipage_pdf.pdf') as pdf:
for i in range(10):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter([0, 1, 2], [0, 1, 2])
pdf.savefig()
plt.close()
...每一个情节都会弹出一个带有实际画布的窗口。是否有一种优雅的解决方案可以跳过屏幕上画布的实际绘制并将绘图直接绘制到多页 pdf 中?
PS:问题仅在 spyder 中运行代码时引起,因此与 spyder 相关,与其他任何内容无关。直接使用 python 运行代码不会导致弹出窗口。
解决方案
我认为您正在寻找的是清除数字。
first_page = plt.figure(figsize=(11.69, 8.27))
first_page.clf()
查看文档:
https ://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.clf.html
一些例子: https ://www.programcreek.com/python/example/102298/matplotlib.pyplot.clf
推荐阅读
- php - 将所有带有标签的帖子加载到数组中 Laravel 雄辩的多态关系
- java - 如何将 log4j 与具有动态文件名的多个附加程序一起使用?
- wpf - 将控件添加到 WPF 中从 SQLite 数据库获取数据的 DataGrid 的自动生成的 ColumnHeader
- javascript - 如何使用 C# 验证 Microsoft MVP 配置文件链接是否有效?
- c++ - C++ 模板错误:在“=”标记之前缺少模板参数
- c# - 将xamarin表单应用程序归档到apk后,它不起作用
- excel - 重新安装windows10后VBA代码不运行
- python - 用 Cython 包装 C 标头宏
- node.js - Botframework V4:后处理中间件
- python - win 7 上的 ucrtbase.dll