Hi,
I find that this similar loop, which uses raw_input() to step through plot 
updates, can be accomplished when run directly from python command-line or 
from ipython, but when run in a Spyder python or ipython console it waits 
until after the loop to show the figure:
 

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: ')

Using time.sleep(), as you have below, does not work when run from a spyder 
console or from python/ipython command lines.


On Thursday, March 1, 2012 7:30:14 PM UTC+1, Andrew Collette wrote:
>
> Hi,
>
> 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
>
>
On Thursday, March 1, 2012 7:30:14 PM UTC+1, Andrew Collette wrote:
>
> Hi,
>
> 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
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"spyder" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/spyderlib/-/pZT0IA1KEVMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/spyderlib?hl=en.

Reply via email to