This Page

Quick search

from__future__importprint_function"""Demonstrate/test the idle and timeout APIWARNING: idle_event is deprecated. Use the animations module instead.This is only tested on gtk so far and is a prototype implementation"""importnumpyasnpimportmatplotlib.pyplotaspltfig,ax=plt.subplots()t=np.arange(0.0,2.0,0.01)y1=np.sin(2*np.pi*t)y2=np.cos(2*np.pi*t)line1,=ax.plot(y1)line2,=ax.plot(y2)N=100defon_idle(event):on_idle.count+=1print('idle',on_idle.count)line1.set_ydata(np.sin(2*np.pi*t*(N-on_idle.count)/float(N)))event.canvas.draw()# test boolean return removalifon_idle.count==N:returnFalsereturnTrueon_idle.cid=Noneon_idle.count=0fig.canvas.mpl_connect('idle_event',on_idle)plt.show()