I have a small python program that takes in data and plots it using matplotlib (v1.3.x). The plot has a draggable legend. It renders fine on Windows, but I get an error on Mac (OS 10.8.3). The code first creates a figure, then uses the figure to create a subplot, which returns an axes. I'm using the axes object to create the legend. Similar to this:

I haven't found anything on the web that can explain this error or why the draggable legend doesn't work on mac. I did find this in the matplotlib documentation: Note that not all kinds of artist are supported by the legend yet, but I don't know if that applies here.

1 Answer
1

It does not work with the osx backend. This backend is still a bit experimental and it is missing several features (e.g. sub-pixel line widths). However, I've just tried and the draggable legend works with the Qt4Agg and GTKAgg backends. Perhaps you have one of these installed? You can switch backends in many ways:

I have tried your options and can't get them to work. For both the backends I'm getting errors about packages/modules not being installed (sip and pygtk). After getting the errors I used macports to install both packages but it doesn't seem like my interactive python can find them.
–
CrystalMay 1 '13 at 14:52

@Crystal: if you're using MacPorts I recommend just getting the Qt4 backend -- I've used it extensively and works well in OS X. You need to install the qt4 variant of matplotlib, something like: port install py-matplotlib +qt4. MacPorts will then install PyQt, sip, and all the required packages.
–
tiagoMay 1 '13 at 14:55

OK... I've done that and I'm still getting the same error - it can't find the sip module. I think my python is importing the wrong matplotlib. I've checked to make sure I'm invoking the correct python, and it is. I can see all of the matplotlib and Qt packages in the frameworks path (macports installed matplotlib v1.2.0), but when I import matplotlib within the interactive python and ask for the version I get v1.3.x. How do I make sure it imports the correct package?
–
CrystalMay 1 '13 at 16:48

On further examination it looks like macports (or something) appended the correct paths to the pythonpath but since matplotlib is still in the previous path it finds v1.3.x first.
–
CrystalMay 1 '13 at 17:12

Finally got it working! Uninstall v1.3.x and python found the right matplotlib. Thanks!
–
CrystalMay 1 '13 at 17:23