I wanted to use pylab for some interactive work (event handling etc), and to use wxpython to drag and drop file names, set parameters and the like. I didn’t really have time/was too lazy to learn how to use the matplotlib api, so I spent some time trying to get the 2 to work together. This works for me in Windows XP.

First, in your matplotlibrc file, set backend to WXAgg (the default TkAgg doesn’t work and WX is slower).

Or do

from matplotlib import use
use('WXAgg')

before you import pylab.

Some have said that you need to set interactive to True, but I prefer to use ion(), ioff() and force draw as follows:

ion() # turn interactive mode on else figure won’t display
figure() # new figure
ioff() # set all values first before drawing because this is slow otherwise

# insert plots etc here #

draw() # force redraw of the figure you’ve created

It seems like that’s all there is to it, though I may have forgotten something…

One Response to “Getting wxPython and matplotlib’s pylab to work together”

Best viewed in Firefox.
2005-6, 2008-present. Version 2.2.
Proudly powered by WordPress.
Entries (RSS) and Comments (RSS).