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:

Figure2

mtdOrigin_panel

miami_pretty_70

np_Regression_withVar2

 

similarity_Small_Yearly

Figure4

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.