Book Image

matplotlib Plotting Cookbook

By : Alexandre Devert
Book Image

matplotlib Plotting Cookbook

By: Alexandre Devert

Overview of this book

Table of Contents (15 chapters)
matplotlib Plotting Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling multiple-page PDF documents


In Chapter 4, Working with Figures, saw seen how to compose several figures in one matplotlib graph. This allows you to create very elaborate plots. When using the PDF output, we have to keep in mind that the graph has to fit on one page. However, with some additional work, we can output PDF documents of several pages. Be warned, matplotlib is a scientific plotting package, not a document composition system, such as LaTeX or ReportLab. Thus, support for multiple pages is fairly minimal. In this recipe, we will see how to generate multiple page PDF documents.

How to do it...

To demonstrate multiple page PDF outputs with matplotlib, let's generate 15 bar charts, with five charts per page. The following script will output a three-page document named barcharts.pdf:

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

# Generate the data
data = np.random.randn(15, 1024)

# The PDF document
pdf_pages = PdfPages...