API Overview

See also the API Changesopen in new window.

Usage patterns

Below we describe several common approaches to plotting with Matplotlib.

The pyplot API

matplotlib.pyplotopen in new window is a collection of command style functions that make Matplotlib work like MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.

pyplotopen in new window is mainly intended for interactive plots and simple cases of programmatic plot generation.

Further reading:

The object-oriented API

At its core, Matplotlib is object-oriented. We recommend directly working with the objects, if you need more control and customization of your plots.

In many cases you will create a Figureopen in new window and one or more Axesopen in new window using pyplot.subplotsopen in new window and from then on only work on these objects. However, it's also possible to create Figureopen in new windows explicitly (e.g. when including them in GUI applications).

Further reading:

The pylab API (disapproved)


Since heavily importing into the global namespace may result in unexpected behavior, the use of pylab is strongly discouraged. Use matplotlib.pyplotopen in new window instead.

pylab is a module that includes matplotlib.pyplotopen in new window, numpyopen in new window and some additional functions within a single namespace. Its original purpose was to mimic a MATLAB-like way of working by importing all functions into the global namespace. This is considered bad style nowadays.


Matplotlib consists of the following submodules:


Toolkitsopen in new window are collections of application-specific functions that extend Matplotlib. The following toolkits are included: