【发布时间】:2014-06-06 16:26:06
【问题描述】:
我正在尝试连续读取文件并使用matplotlib 进行绘图,以创建一些动画。这是工作代码:
import numpy as np
import pylab
import time
print "start"
pylab.ion() # Unfortunately, will still need to run pylab.show() all the time
fig = pylab.figure()
ax = fig.add_subplot(1,1,1)
ax.set_xlim((0,128))
ax.set_ylim((0,128))
#Initialize the circle object to a silly location
f1 = pylab.Circle((60,68), radius=2, fc='y')
ax.add_patch(f1)
pylab.show()
# Start the animation
for i in range(0,1000):
if(i%2 == 0):
f1.center = 30, 30
else:
f1.center = 40, 40
pylab.show()
raw_input("Press Enter to continue...")
print("Updating")
#time.sleep(2) # This is going to be used later
现在,我想用睡眠定时器替换用户输入:
import numpy as np
import pylab
import time
print "start"
pylab.ion() # Unfortunately, will still need to run pylab.show() all the time
fig = pylab.figure()
ax = fig.add_subplot(1,1,1)
ax.set_xlim((0,128))
ax.set_ylim((0,128))
#Initialize the circle object to a silly location
f1 = pylab.Circle((60,68), radius=2, fc='y')
ax.add_patch(f1)
pylab.show()
# Start the animation
for i in range(0,1000):
if(i%2 == 0):
f1.center = 30, 30
else:
f1.center = 40, 40
pylab.show()
#raw_input("Press Enter to continue...")
print("Updating")
time.sleep(2) # This is going to be used later
但是这段代码不起作用!它睡着了,但没有任何更新。我做错了什么?
【问题讨论】:
标签: python python-2.7 matplotlib