Animation doesn't work in Python

2019-08-09 04:00发布

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

1条回答
ら.Afraid
2楼-- · 2019-08-09 04:36

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

查看更多
登录 后发表回答