Skip to content

Instantly share code, notes, and snippets.

@marcelm
Created June 24, 2015 14:23
Show Gist options
  • Save marcelm/c0cbb0b6ee44b471b910 to your computer and use it in GitHub Desktop.
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
"""
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