Skip to content

Instantly share code, notes, and snippets.

@evertrol
Forked from marcelm/pdfpages_oo.py
Last active February 10, 2016 03:49
Show Gist options
  • Save evertrol/fa87e50bd00c71a7c629 to your computer and use it in GitHub Desktop.
Save evertrol/fa87e50bd00c71a7c629 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):
figure = Figure()
axes = figure.add_subplot(1, 1, 1)
axes.plot(np.arange(10), np.random.randn(10))
canvas = FigureCanvasPdf(figure)
canvas.print_figure(pages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment