Search this site


Metadata

Articles

Projects

Presentations

Matplotlib makes me hate.

Let me caveat this rant with the fact that I've only been playing with matplotlib for approximately a week.

All the demos made matplotlib (a python module) look like a great tool that I should want to use to graph things, then I started trying to actually write code and it all went downhill.

Almost all of the functions operate on some mystical global scope, meaning they are by design not threadsafe. Probably not a big deal, I guess, but it certainly feels like an alien world especially given all the object oriented code in use in python.

If this culture shock wasn't bad enough, it went ahead and decided to use inches and ratios as the standard units of measure. You make a figure of a set width and height (in inches) and you can put stuff in that figure given ratio offsets. An offset of '.5' would put your left-bound in the middle. Weird and unexpected. Perhaps not bad. Still, I'm used to pixels, not inches.

Some of the arguments are just looney:

  fig.add_subplot(111)
The docs say this "subplot(211) # 2 rows, 1 column, first (upper) plot". Base10 flag system? What. the. F. I'm at a loss as to why this was ever a good idea. Let's make it hard to add plots? Looks like you can use 'subplot(rows, cols, plotnum)' which is the sensible solution, but all the demos use the integer syntax, and it makes me sad.

You can't easily put the legend outside the graph.

Setting the default font size means you have to set at least 6 things. Make sure you note the excessive use of different tokens for the same freaking setting: labelsize, titlesize, size, and fontsize.

rc("axes", labelsize=10, titlesize=10)
rc("xtick", labelsize=10)
rc("ytick", labelsize=10)
rc("font", size=10)
rc("legend", fontsize=10)

I have code that looks like this:

  fig = figure()
  p = subplot(111)
  line = p.plot_date(dates, values)
  line[0].set_label("foo")
  legend()
  fig.savefig('foo.png', format='png')
Notice my entertaining leaps between OOP and WTF. Other cute nuances are that the docs/examples are littered with:
  ax = subplot(111)
You might think that the name 'ax' means 'axis' and that subplot returns an axis. No. You might ask python with type() and it would say '<type 'instance>'. Helpful. If you just print ax you'll see it is matplotlib.axes.Subplot. I'm trying hard to not get hung up on semantics, but 'axis' to me is very different from a plot. Plot seems like a visual representation, and an axis is a single dimension of a graph (aka a plot).

After several days of playing with this tool, I am frustrated and disheartened. It has such powerful features like tick rules: You can trivially specify "Put one major tick every 3rd week". However, the api is half OO half globally-scoped-procedural. Maybe this is my fault. The docs constantly mix 'matplotlib' and 'pylab' methods. Perhaps you can use just the matplotlib functions by themselves and you don't need pylab? Pylab, by the way, is what provides these awkward global functions and in theory only exists as a pure wrapper on top of matplotlib.


4 responses to 'Matplotlib makes me hate.'

Showing last 4 comments... (Click here to view all comments)

Utkarsh Upadhyay wrote at Tue Dec 18 04:09:52 2007...
I almost totally agree with the problems (preserving the '321' syntax in subplots was rather nice, looking at it the MatLAB user way).

Otherwise, the axis business is a bitter one. I have landed up here becasue I was looking for a way of making different axis subplots, still am looking for one. But just in case you have a better plotting backend, do tell me. ;)

~
musically_ut

John Hunter wrote at Thu Dec 27 13:25:02 2007...
The global mystical state that is agitating you so much is just a thin wrapper on top of maptlotlib's OO API to make it look like matlab.  See http://matplotlib.sf.net/faq.html#OO for guidance. 

JDH

Alan wrote at Tue Nov 11 08:55:24 2008...
Just wondering if you ever followed John's advice? That link is now dead, but you can look at http://matplotlib.sourceforge.net/leftwich_tut.txt to get started. I hope that will encourage you to modify your rant at http://www.semicomplete.com/blog/geekery/matplotlib-induces-self-loathing.html

Alan

Jordan Sissel wrote at Tue Nov 11 19:55:08 2008...
Not yet, I'll check the link you  mentioned and try playing with matplotlib again.


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment: