I ran the script with GTKCairo and it looks fine to me.
> Perhaps you are using GTKAgg which looks like it has the
> problem. My guess is that its caused by using
> gtk.idle_add() which results in asynchronous expose_event
I looked at this briefly and am a little confused by something. The
base class FigureCanvasGTK.expose_event has this in the doc string
"""Expose_event for all GTK backends
Should not be overridden.
but then the derived class
class FigureCanvasGTKAgg(FigureCanvasGTK, FigureCanvasAgg):
does in fact override it.
I inserted a debug print statement into
FigureCanvasGTKAgg.expose_event and it is not called until the loop is
over. I think this is because the call to sleep is preventing the
idle handler from ever getting engaged.
Perhaps Joachim would be better off using a gtk timer to handle his
animation. Basically, matplotlib tries to provide a GUI neutral way
to do animation (eg anim.py) but if you want to do something
semi-sophisticated like alter the timing between draws, you should use
the GUI specific functionality for this, eg gtk timers.
Here is an example
# animate increasing terms in fourier expansion of y=x
from matplotlib.numerix import arange, pi, sin, zeros, Float
def __init__(self, samples=1000, max_k=30):
self.samples = samples
self.max_k = max_k
self.fig = pylab.figure()
self.ax = self.fig.add_subplot(111)
x = arange(0.0, 1.0, 1.0/self.samples)
self.s = zeros((self.max_k,samples), Float)
for k in range(1,self.max_k):
self.s[k] = self.s[k-1]+(-1)**(k+1)*sin(pi*x*k)/k
self.line, = self.ax.plot(x, x*1.3, linewidth=1.0)
self.k = 1
def draw(self, *args):
self.ax.set_title('k = '+str(self.k))
self.k += 1
anim = Animator()