Table Of Contents

Previous topic


Next topic

What’s new in matplotlib

This Page


Here you will find a host of example figures with the code that generated them

Simple Plot

The most basic plot(), with text labels

[source code, hires.png, pdf]


Subplot demo

Multiple regular axes (numrows by numcolumns) are created with the subplot() command.

[source code, hires.png, pdf]



The hist() command automatically generates histograms and will return the bin counts or probabilities

[source code, hires.png, pdf]


Path demo

You can add aribitrary paths in matplotlib as of release 0.98. See the matplotlib.path.

[source code, hires.png, pdf]



The mplot3d toolkit (see mplot3d tutorial and mplot3d Examples) has support for simple 3d graphs including surface, wireframe, scatter, and bar charts (added in matlpotlib-0.99). Thanks to John Porter, Jonathon Taylor and Reinier Heeres for the mplot3d toolkit. The toolkit is included with all standard matplotlib installs.

[source code, hires.png, pdf]



In support of the Phoenix mission to Mars, which used matplotlib in ground tracking of the spacecraft, Michael Droettboom built on work by Charlie Moad to provide an extremely accurate 8-spline approximation to elliptical arcs (see Arc) in the viewport. This provides a scale free, accurate graph of the arc regardless of zoom level

[source code, hires.png, pdf]


Bar charts

The bar() command takes error bars as an optional argument. You can also use up and down bars, stacked bars, candlestick bars, etc, ... See for another example. You can make horizontal bar charts with the barh() command.

[source code, hires.png, pdf]


Pie charts

The pie() command uses a MATLAB compatible syntax to produce pie charts. Optional features include auto-labeling the percentage of area, exploding one or more wedges out from the center of the pie, and a shadow effect. Take a close look at the attached code that produced this figure; nine lines of code.

[source code, hires.png, pdf]


Table demo

The table() command will place a text table on the axes

[source code, hires.png, pdf]


Scatter demo

The scatter() command makes a scatter plot with (optional) size and color arguments. This example plots changes in Google stock price from one day to the next with the sizes coding trading volume and the colors coding price change in day i. Here the alpha attribute is used to make semitransparent circle markers with the Agg backend (see What is a backend?)

[source code, hires.png, pdf]


Slider demo

Matplotlib has basic GUI widgets that are independent of the graphical user interface you are using, allowing you to write cross GUI figures and widgets. See matplotlib.widgets and the widget examples <examples/widgets>

[source code, hires.png, pdf]


Fill demo

The fill() command lets you plot filled polygons. Thanks to Andrew Straw for providing this function

[source code, hires.png, pdf]


Date demo

You can plot date data with major and minor ticks and custom tick formatters for both the major and minor ticks; see matplotlib.ticker and matplotlib.dates for details and usage.

[source code, hires.png, pdf]


Financial charts

You can make much more sophisticated financial plots. This example emulates one of the ChartDirector financial plots. Some of the data in the plot, are real financial data, some are random traces that I used since the goal was to illustrate plotting techniques, not market analysis!

[source code, hires.png, pdf]


Basemap demo

Jeff Whitaker provided this example showing how to efficiently plot a collection of lines over a colormap image using the Basemap . Many map projections are handled via the proj4 library: cylindrical equidistant, mercator, lambert conformal conic, lambert azimuthal equal area, albers equal area conic and stereographic. See the tutorial entry on the wiki.

[source code]

Exception occurred rendering plot.

Log plots

The semilogx(), semilogy() and loglog() functions generate log scaling on the respective axes. The lower subplot uses a base10 log on the xaxis and a base 4 log on the yaxis. Thanks to Andrew Straw, Darren Dale and Gregory Lielens for contributions to the log scaling infrastructure.

[source code, hires.png, pdf]


Polar plots

The polar() command generates polar plots.

[source code, hires.png, pdf]



The legend() command automatically generates figure legends, with MATLAB compatible legend placement commands. Thanks to Charles Twardy for input on the legend command

[source code, hires.png, pdf]



A sampling of the many TeX expressions now supported by matplotlib’s internal mathtext engine. The mathtext module provides TeX style mathematical expressions using freetype2 and the BaKoMa computer modern or STIX fonts. See the matplotlib.mathtext module for additional. matplotlib mathtext is an independent implementation, and does not required TeX or any external packages installed on your computer. See the tutorial at Writing mathematical expressions.

[source code, hires.png, pdf]


Native TeX rendering

Although matplotlib’s internal math rendering engine is quite powerful, sometimes you need TeX, and matplotlib supports external TeX rendering of strings with the usetex option.

[source code, hires.png, pdf]


EEG demo

You can embed matplotlib into pygtk, wxpython, Tk, FLTK or Qt applications. Here is a screenshot of an eeg viewer called pbrain which is part of the NeuroImaging in Python suite NIPY. Pbrain is written in pygtk using matplotlib. The lower axes uses specgram() to plot the spectrogram of one of the EEG channels. For an example of how to use the navigation toolbar in your applications, see user_interfaces example code: If you want to use matplotlib in a wx application, see user_interfaces example code: If you want to work with glade, see user_interfaces example code: