Hi,
I'm trying to embed matplotlib on WX (which seems to work well for the=20
moment). I'd like to avoid the wx mainloop() by making it run in a=20
different thread than that of my main program.
The classical way of doing (using show() ) doesn't work. The first time,=20
the figure becomes the main thread and my program stops running until I=20
close the window. The second time I call it though, my program remains=20
the main thread... Check the following code
import threading
import matplotlib
matplotlib.use('WX')
from matplotlib.pylab import *
def f():
fig =3D Figure(figsize=3D(8,6))
data =3D range(10)
plot(data)
show()
f()
print 'here'
f()
print 'here'
f()
The screen prints 'here' only after closing the figure with the mouse.=20
Then second figure appears, but the screen prints 'end' without me=20
having to close the figure like the first one. The third figure though=20
does not appear at all!
What am I doing wrong? I know I can use the show command only once, but=20
my program runs sequently and I need to plot data while it runs. I also=20
tried to run this function in a different thread but the results are=20
similar :
t =3D threading.Thread(target =3D f)
t.start()
print 'here'
tt =3D threading.Thread(target =3D f)
tt.start()
print 'end'
If the last three lines are neglected (plot only once), then it works=20
perfectly! My main program terminates its execution and the figure stays=20
alive until I close it. When f() is called two times though, both=20
windows close when my program terminates...
Does anyone have an idea of how I should do this?
Thanks in advance,
Kosta
PS: I also ttried the example embedding-in-wx-2.py which seems to be=20
exactly my case for embedding my program in a GUI. The best would be=20
running that example in a different thread or something like that in=20
order to avoid the mainloop(). Any ideas?
--=20
Kosta Gaitanis
Laboratoire de T=E9l=E9communications et T=E9l=E9d=E9tection - TELE
Universit=E9 catholique de Louvain UCL - FSA / ELEC
B=E2timent Stevin, a.156
Place du Levant, 2
B-1348 Louvain-La-Neuve, Belgium
Tel: +32 10/47.80.75
e-mail: gai...@te...=20
|