I'm transitioning from using IDL to using Python for analysis.
There's one (important) thing I can't get working, which is plotting
from a loop or script. The simplest fragment I could find that
reproduces the problem is:
import numpy as np
import time
import pylab as p
a = np.arange(10)
for x in xrange(10):
p.plot(x)
time.sleep(1)
Whether in a .py file or entered manually at the console, the result
is the same: a plot window appears but is blank and frozen (won't
respond to clicks); when the loop exits, all ten plots suddenly show
up in the figure at once.
I've tried various combinations of pylab.ion(), draw(), show() with no
success. This is a real problem as it's very common in the IDL world
to plot many time series one after another, sometimes reading input
from the user for each one. For example, I need to manually go
through a dataset and throw out the bad traces, using input() in place
of the sleep command.
Any ideas? I am using Spyder 2.0.13 as part of PythonXY.
Thanks,
Andrew Collette
import numpy as np
#import time
import pylab as p
a = np.arange(10)
for x in xrange(5):
p.figure()
p.plot(a)
> two changes that made it work for me:
>
> import numpy as np
>
> #import time
>
> import pylab as p
>
> a = np.arange(10)
>
> for x in xrange(5):
>
> p.figure()
>
> p.plot(a)
I tried this, and it created ten empty windows one at a time, all of
which are blank until the loop finishes. There's something about how
the plot command works that doesn't actually draw anything until the
script is over. ion() and p.draw() don't seem to do anything when put
in the script.
Andrew
import numpy as np
import time
import pylab as p
a = np.arange(10)
for x in xrange(3):
p.figure()
p.plot(a)
p.draw()
p.draw()
p.show()
time.sleep(2)
import numpy as np
import pylab as p
p.ion()
for x in xrange(1,10):
p.plot(np.linspace(x,x*2,10),np.linspace(0,x,10))
p.show()
raw_input('input: ')
In your code, simply replace this:
time.sleep(1)
by that:
p.waitforbuttonpress(1)
Using time.sleep will freeze the GUI because it will block the scripts
execution hence preventing the Qt event loop from processing events
and updating the GUI.
HTH,
Pierre
> --
> You received this message because you are subscribed to the Google Groups "spyder" group.
> To post to this group, send email to spyd...@googlegroups.com.
> To unsubscribe from this group, send email to spyderlib+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spyderlib?hl=en.
>
Awesome! Thanks; this makes analysis in Python so much easier.
Andrew