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.

Revisions

  1. marcelm created this gist Jun 24, 2015.
    15 changes: 15 additions & 0 deletions pdfpages_oo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    """
    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)