So I've copied the example given here and when I run it I get:
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__
So where do I go from here? Thanks
PdfPages
has become a context manager only in version 1.3.1. See the chagelog .
In particular, observe the following line:
Added a context manager for creating multi-page pdfs (see
matplotlib.backends.backend_pdf.PdfPages
).
In addition to the accepted answer, I had to do this:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
And also avoid using plt.figure()
which invokes the display.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.