[Matplotlib-users] [Fwd: simple animation question] From: Andres Luhamaa - 2007-09-05 09:48 ```Hi all! I'm new to matplotlib so please excuse me, if this is a bit too simple problem. I'm trying to animate simple plot using example anim.py It works well when I just write functions as follows: def joonista(x): line, = p.plot(ala, x) p.draw() time.sleep(0.1) def lpc(x): x2=empty(real(ap)) for t in range(maxt): x2[alg]=x[alg+1] x2[ap-1]=x[alg] for k in range(alg+1,ap-1): x2[k]=x[k+1] x=x2 joonista(x2) but when I write the functions in a more general way and define an additional function "lpc1" to make some calculation, like this: def joonista(x): line, = p.plot(ala, x) p.draw() time.sleep(0.1) def lpc(x): x2=empty(real(ap)) for t in range(maxt): x2=lpc1(x) x=x2 joonista(x2) def lpc1(x): x2=empty(real(ap)) x2[alg]=x[alg+1] x2[ap-1]=x[alg] for k in range(alg+1,ap-1): x2[k]=x[k+1] return x2 the animation still works, but the plot does not clear itself at all, meaning that all the lines it draws stay there until the end. I'm using matplotlib version 0.87.1 which comes with ubuntu. The full code is added in the end. So is this expected behavior and I should make the code in a different way or what? I could try to upgrade to newer version of matplotlib if that could be useful. Regards, Andres The full program code: #!/usr/bin/env python import pylab as p from numpy import * import time def joonista(x): line, = p.plot(ala, x) p.draw() time.sleep(0.1) def gaussikover(): for i in ala: x[i]=math.exp(-(i-ap2)**2./a) return x def lpc(x): x2=empty(real(ap)) for t in range(maxt): ## x2[alg]=x[alg+1] ## x2[ap-1]=x[alg] ## for k in range(alg+1,ap-1): ## x2[k]=x[k+1] x2=lpc1(x) x=x2 joonista(x2) def lpc1(x): x2=empty(real(ap)) x2[alg]=x[alg+1] x2[ap-1]=x[alg] for k in range(alg+1,ap-1): x2[k]=x[k+1] return x2 p.ion() alg=0 ap=100 ap2=ap/2 x=empty(real(ap)) a=70. maxt=20 ala=range(ap) x=gaussikover() lpc(x) ```