Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8b69b80

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

File tree

Expand file treeCollapse file tree

1 file changed

+17
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-0
lines changed

‎examples/pylab_examples/multipage_pdf.py

Copy file name to clipboardExpand all lines: examples/pylab_examples/multipage_pdf.py
+17Lines changed: 17 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.