matplotlib.pyplot/pylab not updating figure while isinteractive(), using ipython -pylab

from pylab import *
import time
ion()
tstart = time.time()               # for profiling
x = arange(0,2*pi,0.01)            # x-array
line, = plot(x,sin(x))
for i in arange(1,200):
    line.set_ydata(sin(x+i/10.0))  # update the data
    draw()                         # redraw the canvas
    pause(0.01)
print 'FPS:' , 200/(time.time()-tstart)
ioff()
show()

######################## The above worked for me nicely. I ran it in spyder editor in pythonxy2.7.3 under win7 OS.
Note the pause() statement following draw() followed by ioff() and show().


The second answer to the question you linked provides the answer: call draw() after every plot() to make it appear immediately; for example:

import time
ion()
x = linspace(-1,1,51)
plot(sin(x))
for i in range(10):
    plot([sin(i+j) for j in x])
    # make it appear immediately
    draw()
    time.sleep(1)

If that doesn't work... try what they do on this page: http://www.scipy.org/Cookbook/Matplotlib/Animations

import time

ion()

tstart = time.time()               # for profiling
x = arange(0,2*pi,0.01)            # x-array
line, = plot(x,sin(x))
for i in arange(1,200):
    line.set_ydata(sin(x+i/10.0))  # update the data
    draw()                         # redraw the canvas

print 'FPS:' , 200/(time.time()-tstart)

The page mentions that the line.set_ydata() function is the key part.


had the exact same problem with ipython running on my mac. (Enthought Distribution of python 2.7 32bit on Macbook pro running snow leopard).

Got a tip from a friend at work. Run ipython from the terminal with the following arguments:

ipython -wthread -pylab

This works for me. The above python code from "Daniel G" runs without incident, whereas previously it didn't update the plot.

According to the ipython documentation:

[-gthread, -qthread, -q4thread, -wthread, -pylab:...] They provide threading support for the GTK, Qt (versions 3 and 4) and WXPython toolkits, and for the matplotlib library.

I don't know why that is important, but it works.

hope that is helpful, labjunky