In Defense of Matplotlib

I’ve been doing some reading, and I’ve discovered that a lot of people don’t like matplotlib. Specifically, it seems that the default settings are a big turn off, and I agree. They are pretty hideous. There are a lot of ongoing projects that attempt to rectify matplotlib, or reinvent Python plotting altogether, including Plotly, CairoPlot, Veusz, prettyplotlibSeaborn (which appears to mimic R’s ggplot2), and ggplot itself (which is working to port over R’s ggplot). Some of these are complete language overhauls (Plotly, CairoPlot, Veusz, ggplot) and others are built on matplotlib (Seaborn, prettyplotlib). Either way, there’s a lot of effort being devoted to replacing or redesigning matplotlib. I understand some of it. The matplotlib language is difficult and it’s default settings are horrendous. It takes a lot of tweaking to get to something workable. That being said, matplotlib is so infinitely customizable so that it is capable of making some pretty awesome graphs.

Yes, it takes a bit of work, but because matplotlib is so infinitely customizable, you can make matplotlib graphs look absolutely fantastic. Here are some of my favorites that I’ve made:








I’m proud of the panel plots, in particular. Using a for() loop and some general programming, I can make that panel/lattice plot in about 28 lines of code. It takes me roughly the same number of lines to make both panel plots presented above.

So, although it takes some work, I really see nothing wrong with matplotlib. It works very well, it’s mature, it is more flexible than some of the other modules, and can make some graphs that look pretty outstanding.

That said, I’m still excited for ggplot to be finished. The ability to calculate statistics within the plotting framework (as in the stat_summary() function) and the ease of lattice plots have always appealed to me. Plus, the grammer of graphics language makes a lot of sense and is more intuitive than matplotlib.




9 thoughts on “In Defense of Matplotlib

  1. I agree with you. Matplotlib is awesome. But it would be nice to have some nice defaults. Matplotlib seems to mimic very closely the (bad) aesthetic decisions of matlab. I think it would be nice to provide some better defaults. (or at least a library that changes the defaults to a nicer thing).

    • I completely agree. I find that’s the case with most graphing packages. Matplotlib, R base plot, and ggplot2 all have some pretty strange defaults. I love the syntax of ggplot2, but sometimes it takes me 20 lines of code just to get a publication-quality scatterplot by messing with the theme() options. So offhand, I do not find ggplot2 to necessarily be any more efficient than matplotlib at making nice figures. R’s base plot defaults are even worse. So my experience has been that almost all graphs need excessive tweaking to get right, and matplotlib is no more difficult or intensive than R in that regard.

  2. You forgot to mention Bokeh ( in your list. We all love MPL but if you need interaction, native web publishing, streaming or bug data, new solutions are needed.

  3. You forgot to mention Bokeh ( in your list of alternatives! We all love MPL but for interactive, web published streaming or big data new tools are needed.

      • [Disclaimer: I am a Bokeh core dev, also I have never used personally]

        They have some similarities, for sure. Both are cross-language plotting platforms for publishing interactive charts to the web. But also some differences. is a commercial product with a cloud-hosted plot-publishing service. It also has more language bindings, and probably a bit more polish in some aspects. Bokeh is open-source (BSD licensed), and I believe it is tilted a bit more towards techniques for handling streaming and large data as well as dashboarding. Bokeh does not have a cloud service offering, but you can run your own Bokeh server on-premise or in the cloud to host plots.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s