繁体   English   中英

matplotlib pdf savefig提前退出

[英]matplotlib pdf savefig exiting early

所以我复制了这里给出的示例,运行时我得到:

Traceback (most recent call last):
  File "C:\Users\User\Documents\Project work\pdf.py", line 9, in <module>
    with PdfPages('multipage_pdf.pdf') as pdf:
AttributeError: __exit__

那我从这里去哪里呢? 谢谢

PdfPages仅在版本1.3.1中才成为上下文管理器。 参见chagelog

特别要注意以下几行:

添加了用于创建多页pdf的上下文管理器(请参见matplotlib.backends.backend_pdf.PdfPages )。

除了可接受的答案,我还必须这样做:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

还要避免使用调用显示的plt.figure()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM