有没有办法使在matplotlib上绘制的剧情像电影一样循环?如果我有12个不同的情节,并且让它显示第一个情节10秒钟,然后显示下一个情节,依此类推,然后在最后一个情节之后重复?由于要显示的地块数量众多,我想以此代替子图。
是的,将动画模块与配合使用,repeat = True
并通过修改interval
参数来控制绘图之间的时间。
import matplotlib.animation as animation
fig = plt.figure()#
data_, = plot([], [])
def data_gen():
while i < NUMBER_OF_PLOTS:
'''
make your instance of X data in a list called YOUR_X_DATA
and your Y data in a list called YOUR_Y_DATA
and iterate along it.
'''
yield YOUR_X_DATA[i], YOUR_Y_DATA[i]
i+=1
def run(data):
data_.set_data(data[0], data[1])
ani = animation.FuncAnimation(fig , run, data_gen, interval=100,repeat=True)
plt.show()
或使用time.sleep(10)
和plt.close(fig)
这种方式
import time
# suppose you have fig1, fi2, fig 3 etc.
while(True):
time.sleep(10)
plt.close(fig1)
# import the next plot
time.sleep(10)
plt.close(fig2)
# import the next plot
time.sleep(10)
plt.close(fig3)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句