Created
June 24, 2015 14:23
-
-
Save marcelm/c0cbb0b6ee44b471b910 to your computer and use it in GitHub Desktop.
Plot multiple figures into a single PDF with matplotlib, using the object-oriented interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Plot multiple figures into a single PDF with matplotlib, using the | |
object-oriented interface. | |
""" | |
from matplotlib.backends.backend_pdf import FigureCanvasPdf, PdfPages | |
from matplotlib.figure import Figure | |
import numpy as np | |
with PdfPages('multi.pdf') as pages: | |
for i in range(10): | |
fig = Figure() | |
ax = fig.gca() | |
ax.plot(np.arange(10), np.random.randn(10)) | |
canvas = FigureCanvasPdf(fig) | |
canvas.print_figure(pages) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment