You are reading an old version of the documentation (v1.3.0). For the latest version see

Previous topic


Next topic


This Page


A PDF matplotlib backend Author: Jouni K Seppänen <>

class matplotlib.backends.backend_pdf.FigureCanvasPdf(figure)

Bases: matplotlib.backend_bases.FigureCanvasBase

The canvas the figure renders into. Calls the draw and print fig methods, creates the renderers, etc...

Public attribute

figure - A Figure instance
class matplotlib.backends.backend_pdf.Name(name)

Bases: object

PDF name object.

class matplotlib.backends.backend_pdf.Operator(op)

Bases: object

PDF operator object.

class matplotlib.backends.backend_pdf.PdfFile(filename)

Bases: object

PDF file object.


Return name of an ExtGState that sets alpha to the given value

embedTTF(filename, characters)

Embed the TTF font from the named file into the document.


Select a font based on fontprop and return a name suitable for Op.selectfont. If fontprop is a string, it will be interpreted as the filename (or dvi name) of the font.


Return name of an image XObject representing the given image.

markerObject(path, trans, fillp, strokep, lw, joinstyle, capstyle)

Return name of a marker XObject representing the given path.


Reserve an ID for an indirect object. The name is used for debugging in case we forget to print out the object with writeObject.


Write out the info dictionary, checking it for good form


Write out the PDF trailer.


Write out the xref table.

class matplotlib.backends.backend_pdf.PdfPages(filename)

Bases: object

A multi-page PDF file.

Use like this:

# Initialize:
pp = PdfPages('foo.pdf')

# As many times as you like, create a figure fig, then either:
fig.savefig(pp, format='pdf') # note the format argument!
# or:

# Once you are done, remember to close the object:

(In reality PdfPages is a thin wrapper around PdfFile, in order to avoid confusion when using savefig and forgetting the format argument.)

Create a new PdfPages object that will be written to the file named filename. The file is opened at once and any older file with the same name is overwritten.


Finalize this object, making the underlying file a complete PDF file.


Return a modifiable information dictionary object (see PDF reference section 10.2.1 ‘Document Information Dictionary’).

savefig(figure=None, **kwargs)

Save the Figure instance figure to this file as a new page. If figure is a number, the figure instance is looked up by number, and if figure is None, the active figure is saved. Any other keyword arguments are passed to Figure.savefig.

class matplotlib.backends.backend_pdf.Reference(id)

Bases: object

PDF reference object. Use PdfFile.reserveObject() to create References.

class matplotlib.backends.backend_pdf.Stream(id, len, file, extra=None)

Bases: object

PDF stream object.

This has no pdfRepr method. Instead, call begin(), then output the contents of the stream by calling write(), and finally call end().

id: object id of stream; len: an unused Reference object for the length of the stream, or None (to use a memory buffer); file: a PdfFile; extra: a dictionary of extra key-value pairs to include in the stream header


Finalize stream.


Write some data on the stream.

matplotlib.backends.backend_pdf.fill(strings, linelen=75)

Make one string from sequence of strings, with whitespace in between. The whitespace is chosen to form lines of at most linelen characters, if possible.

matplotlib.backends.backend_pdf.new_figure_manager(num, *args, **kwargs)

Create a new figure manager instance

matplotlib.backends.backend_pdf.new_figure_manager_given_figure(num, figure)

Create a new figure manager instance for the given figure.


Map Python objects to PDF syntax.