Interactive Matplotlib Through Eclipse PyDev
Solution 1:
You can solve this problem by selecting a GUI for the Interactive Console in PyDev Preference.
Eclipse -> Window -> Preferences -> Pydev -> Interactive Console -> Enable GUI event loop integration.
In my case, I chose PyQt (qt/qt4)
Solution 2:
Apologies for the potentially incomplete answer, but hopefully I will be able to shed some light on the problem.
I believe that the one that the OP describes is normal behaviour. In fact, starting from the command line ipython, importing pylab and issuing a plot command produces exactly the blocking behaviour described, so this is not related to pydev or eclipse. The fact is that show in matplotlib is blocking in interactive mode; when you use matplotlib in a ipython session started as "ipython --pylab", you are taking advantage of some "hacks" that the ipython developers did for you around matplotlib, allowing to have both an interactive mode and non blocking calls. However, importing pylab is not enough to apply these "hacks". PyDev does not seems to allow flags to the interpreter call, so one can't directly invoke "ipython --pylab".
Luckily, ipython has a special command "pylab" that applies the hacks and imports pylab even if the interpreter was not started with the pylab flag. So you can just try to type "pylab" inside the console (actually, you can even customize your pydev console so that it is done automatically) and you should get the desired behaviour. However, I must report that while this works fine for me from a ipython session started from the command line, something goes wrong when I try to do the same from inside Eclipse. The command doesn't block, I get the python icon but the matplotlib window doesn't show up. For the records, I am on a Mac running Snow Leopard. I am not able to tell if the same problem happens also in Windows, that the OP seems to be using.
Solution 3:
I achieve similar behave in Eclipse PyDev by executing plotting function in another thread:
import threading
from pylab import *
import matplotlib.animation as animation
import time
x = array(range(0,1000))/100
y = sin(x)
def updateData(self):
ax.set_data(x,y)
def MyThread():
global ax
fig, axarr = subplots(1)
ax, = axarr.plot(x,y)
simulation = animation.FuncAnimation(fig, updateData)
show()
t = threading.Thread(target=MyThread)
t.start()
# console stay active, user can interactively control figure
time.sleep(1)
y = sin(2*x)
time.sleep(2)
ax.get_axes().grid()
ax.get_axes().set_xlabel("time")
Tested with toolchain Eclipse 4.3, PyDev 2.7.1, Python 3.2, IPython 0.13
Solution 4:
Just use the %matplotlib
magic-command to activate interactive plotting (exactly what you described).
The pylab
command imports numpy.*
and pylab.*
, seriously polluting your global namespace.
Post a Comment for "Interactive Matplotlib Through Eclipse PyDev"