views:

474

answers:

2

Hi, I regularly make figures (the exploratory data analysis type) in R. I also program in Python and was wondering if there are features or concepts in matplotlib that would be worth learning. For instance, I am quite happy with R - but its image() function will produce large files with pixelated output, whereas Matlab's equivalent figure (I also program regularly in Matlab) seems to be manageable in file size and also 'smoothed' - does matplotlib also provide such reductions...? But more generally, I wonder what other advantages matplotlib might confer. I don't mean this to be a trolling question. Thanks.

+4  A: 

This is a tough one to answer.

I recently switched some of my graphing workload from R to matplotlib. In my humble opinion, I find matplotlib's graphs to be prettier (better default colors, they look crisper and more modern). I also think matplotlib renders PNGs a whole lot better.

The real motivation for me though, was that I wanted to work with my underlying data in Python (and numpy) and not R. I think this is the big question to ask, in which language do you want to load, parse and manipulate your data?

On the other hand, a bonus for R is that the plotting defaults just work (there's a function for everything). I find myself frequently digging through the matplotlib docs (they are thick) looking for some obscure way to adjust a border or increase a line thickness. R's plotting routines have some maturity behind them.

Mark
Thanks for your thoughts... I do plot in Matlab also so I thought it might be an easy transition, but I can create most graphics I can imagine in R (especially with grid graphics) so I suppose I'll hold off on matplotlib - I forget there are details in customization to learn in every package and that would be an unwanted time sink at the moment...
Stephen
+2  A: 

I think that the largest advantage is that matplotlib is based on Python, which you say you already know. So, this is one language less to learn. Just spend the time mastering Python, and you'll benefit both directly for the plotting task at hand and indirectly for your other Python needs.

Besides, IMHO Python is an overall richer language than R, with far more libraries that can help for various tasks. You have to access data for plotting, and data comes in many forms. In whatever form it comes I'm sure Python has an efficient library for it.

And how about embedding those plots in more complete programs, say simple GUIs? matplotlib binds easily with Python's GUI libs (like PyQT) and you can make stuff that only your imagination limits.

Eli Bendersky
Thanks for your thoughts - despite Python being richer than R, I am more comfortable with R in many respects: its built-in list can also be an ordered dictionary, quick creation of temporary environments (namespaces) for local computation, powerful anonymous functions... GUI creation is a '+' for Python - I do use it with Matlab-generated plots + PIL sometimes but I also make simple GUIs in R for interactive analysis.
Stephen