You are reading an old version of the documentation (v2.2.0). For the latest version see
Version 2.2.0
Fork me on GitHub

Table Of Contents

Related Topics

This Page

Matplotlib API

These examples use the Matplotlib api rather than the pylab/pyplot procedural state machine. For robust, production level scripts, or for applications or web application servers, we recommend you use the Matplotlib API directly as it gives you the maximum control over your figures, axes and plottng commands.

The example is the simplest example of using the Agg backend which is readily ported to other output formats. This example is a good starting point if your are a web application developer. Many of the other examples in this directory use matplotlib.pyplot just to create the figure and show calls, and use the API for everything else. This is a good solution for production quality scripts. For full fledged GUI applications, see the user_interfaces examples.


For more in-depth information about the colormaps available in matplotlib as well as a description of their properties, see the colormaps tutorial.

Event Handling

Matplotlib supports event handling with a GUI neutral event model, so you can connect to Matplotlib events without knowledge of what user interface Matplotlib will ultimately be plugged in to. This has two advantages: the code you write will be more portable, and Matplotlib events are aware of things like data coordinate space and which axes the event occurs in so you don’t have to mess with low level transformation details to go from canvas space to data space. Object picking examples are also included.

Our Favorite Recipes

Here is a collection of short tutorials, examples and code snippets that illustrate some of the useful idioms and tricks to make snazzier figures and overcome some matplotlib warts.


These examples cover how different scales are handled in Matplotlib.

Embedding Matplotlib in graphical user interfaces

You can embed Matplotlib directly into a user interface application by following the examples here. Currently matplotlib supports wxpython, pygtk, tkinter and pyqt4/5.

When embedding Matplotlib in a GUI, you must use the Matplotlib API directly rather than the pylab/pyplot proceedural interface, so take a look at the examples/api directory for some example code working with the API.