Matplotlib: An Open Source Python 2-D Plotting Library

Submitted by jconners on Mon, 12/14/2009 - 18:47.

James Conners, CCE / PAL

There are plenty of libraries available for producing plots of data. Some are built into proprietary application environments like Matlab (http://www.mathworks.com/) or offered as a service on the web like Google Charts (http://code.google.com/apis/chart/). The majority of others are written in a particular programming language over pre-existing or custom graphic and other supporting libraries, like PLplot (http://plplot.sourceforge.net/), Gnuplot (http://www.gnuplot.info/) or JPGraph (http://www.aditus.nu/jpgraph/). Matplotlib is in the last group of libraries, written in Python and dependent primarily on the Numpy (http://numpy.scipy.org/) scientific computing package. It's open source and maintained by an active community of developers and users.

After using JPGraph for about three years to produce dynamic plots of data on our web sites, we've recently switched to Matplotlib. We made the change to an implementation using Matplotlib because of the greater variety of plots available and the improved performance with large datasets. One of our first activities was to build a web service using a set of plotting classes abstracting the library's application interface. Hooking the library's functionality into a web architecture is a pretty simple process using either the mod_python (http://www.modpython.org/) Apache module or Python's CGI interface. Another way to use Matplotlib is within an interactive shell – such as the built-in Python interpretor or a more advanced one like iPython (http://ipython.scoi_events.xlsxipy.org/moin/). These shells allow you to create and manipulate plots using the pylab interface, a procedural set of functions built over the Matplotlib API that feels like the Matlab graphics interface. The higher-level programming interface works well for quicker implementations while the extensive object-oriented API provides the flexibility for building more customizable plotting routines. There are also additional toolkits available for download that supplement the library with capabilities like 3-D graphics and plotting over maps.

There are always going to be cases where your preferred plotting library or application is either inadequate or comes with too much overhead for what you need. From our experience so far with Matplotlib, the library seems to strike a good balance in being flexible enough to handle the majority of visualization tasks while still being a good choice for small one-time tasks that require a quick view into the data. Since the community of developers and users seems to be stable, if not growing, there has recently been more documentation available for help on getting started with the library, as well as a new book (see Resources) recently published, easing the learning curve a bit. At this time, it fits our needs as a quality plotting library with an active development and support trajectory.

Resources:

Matplotlib home page: The site contains documentation, galleries, user-contributed how-to's, etc.
[http://matplotlib.sourceforge.net/]

Matplotlib book:
[http://www.amazon.com/Matplotlib-Python-Developers-Sandro-Tosi/sim/1847197906/2]

SciPy Matplotlib Cookbook: Quick examples to follow when getting started making plots
[http://www.scipy.org/Cookbook/Matplotlib]

Matplotlib mailing lists:
[http://sourceforge.net/mail/?group_id=80706]

Video Lecture given by the Matplotlib creator:
[http://videolectures.net/mloss08_hunter_mat/]

| »