2015-05-22 44 views
1

有没有办法让它在matplotlib上制作的情节会像电影一样循环?如果我有12个不同的情节,并显示第一个10秒,然后下一个等,然后在最后一个之后重复?由于我想展示的情节数量多,我希望将其作为子情节的替代方案。使用matplotlib骑自行车的情节

+0

matplotlib有一个'animation'模块,来看看这个例子:http://matplotlib.org/1.4.2/examples /animation/basic_example.html – heltonbiker

回答

3

是的,使用动画模块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() 

OR使用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) 
+0

这应该工作。是否有可能使它每次有人点击鼠标或按下空间时都会改变? – greenthumbtack

+0

你的意思是“”去“下一个图”通过“更改”? – farhawa

+0

是的,我很抱歉 – greenthumbtack