API Overview
See also the API Changes.
Usage patterns
Below we describe several common approaches to plotting with Matplotlib.
The pyplot API
matplotlib.pyplot 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.
pyplot is mainly intended for interactive plots and simple cases of programmatic plot generation.
Further reading:
- The
matplotlib.pyplotfunction reference - Pyplot tutorial
- Pyplot examples
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 Figure and one or more Axes using pyplot.subplots and from then on only work on these objects. However, it's also possible to create Figures explicitly (e.g. when including them in GUI applications).
Further reading:
-
matplotlib.axes.Axesandmatplotlib.figure.Figurefor an overview of plotting functions. - Most of the examples use the object-oriented approach (except for the pyplot section)
The pylab API (disapproved)
Warning
Since heavily importing into the global namespace may result in unexpected behavior, the use of pylab is strongly discouraged. Use matplotlib.pyplot instead.
pylab is a module that includes matplotlib.pyplot, numpy, numpy.fft, numpy.linalg, numpy.random, and some additional functions, all 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.
Modules
Matplotlib consists of the following submodules:
matplotlibmatplotlib.afmmatplotlib.animationmatplotlib.artistmatplotlib.axesmatplotlib.axismatplotlib.backend_basesmatplotlib.backend_managersmatplotlib.backend_toolsmatplotlib.backendsmatplotlib.beziermatplotlib.blocking_inputmatplotlib.categorymatplotlib.cbookmatplotlib.cmmatplotlib.collectionsmatplotlib.colorbarmatplotlib.colorsmatplotlib.containermatplotlib.contourmatplotlib.datesmatplotlib.dvireadmatplotlib.figurematplotlib.font_managermatplotlib.fontconfig_patternmatplotlib.gridspecmatplotlib.imagematplotlib.legendmatplotlib.legend_handlermatplotlib.linesmatplotlib.markersmatplotlib.mathtextmatplotlib.mlabmatplotlib.offsetboxmatplotlib.patchesmatplotlib.pathmatplotlib.patheffectsmatplotlib.pyplotmatplotlib.projectionsmatplotlib.projections.polarmatplotlib.quivermatplotlib.rcsetupmatplotlib.sankeymatplotlib.scalematplotlib.sphinxext.plot_directivematplotlib.spinesmatplotlib.stylematplotlib.tablematplotlib.testingmatplotlib.textmatplotlib.texmanagermatplotlib.textpathmatplotlib.tickermatplotlib.tight_layoutmatplotlib.transformsmatplotlib.trimatplotlib.type1fontmatplotlib.unitsmatplotlib.widgets
Toolkits
Toolkits are collections of application-specific functions that extend Matplotlib. The following toolkits are included:
- mplot3d API
- Matplotlib axes_grid1 Toolkit
- Matplotlib axisartist Toolkit
- Matplotlib axes_grid Toolkit
© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.3.3/api/index.html