Skip to content

Commit 8b69b80

Browse files
committed
multipage pdf: show usage of with statement in example
1 parent 5cb2840 commit 8b69b80

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

examples/pylab_examples/multipage_pdf.py

+17
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,20 @@
4141

4242
# Remember to close the object - otherwise the file will not be usable
4343
pdf.close()
44+
45+
# Or use the with statement, the file gets properly closed at the end:
46+
with PdfPages('multipage_pdf2.pdf') as pdf:
47+
48+
figure(figsize=(3, 3))
49+
plot(range(7), [3, 1, 4, 1, 5, 9, 2], 'r-o')
50+
title('Page One')
51+
pdf.savefig()
52+
close()
53+
54+
rc('text', usetex=True)
55+
figure(figsize=(8, 6))
56+
x = np.arange(0, 5, 0.1)
57+
plot(x, np.sin(x), 'b-')
58+
title('Page Two')
59+
pdf.savefig()
60+
close()

0 commit comments

Comments
 (0)