Dims
Dims

Reputation: 51039

Animation doesn't work in Python

Where is normal explanation on how to plot animated graphs in Python?

I wrote this

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,200000):
    line.set_ydata(sin(x+i/10.0))  # update the data
    draw()                         # redraw the canvas

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

and got just white window

enter image description here

Upvotes: 1

Views: 156

Answers (1)

Dadep
Dadep

Reputation: 2788

try :

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,200000):
    line.set_ydata(sin(x+i/10.0))  # update the data
    draw()                         # redraw the canvas
    pause(0.5)

With pause time in second

Upvotes: 1

Related Questions