Note

Go to the endto download the full example code.

Animated image using a precomputed list of images#

Output generated viamatplotlib.animation.Animation.to_jshtml.

importmatplotlib.pyplotaspltimportnumpyasnpimportmatplotlib.animationasanimationfig,ax=plt.subplots()deff(x,y):returnnp.sin(x)+np.cos(y)x=np.linspace(0,2*np.pi,120)y=np.linspace(0,2*np.pi,100).reshape(-1,1)# ims is a list of lists, each row is a list of artists to draw in the# current frame; here we are just animating one artist, the image, in# each frameims=[]foriinrange(60):x+=np.pi/15y+=np.pi/30im=ax.imshow(f(x,y),animated=True)ifi==0:ax.imshow(f(x,y))# show an initial one firstims.append([im])ani=animation.ArtistAnimation(fig,ims,interval=50,blit=True,repeat_delay=1000)# To save the animation, use e.g.## ani.save("movie.mp4")## or## writer = animation.FFMpegWriter(#     fps=15, metadata=dict(artist='Me'), bitrate=1800)# ani.save("movie.mp4", writer=writer)plt.show()

Tags:component: animation

Total running time of the script: (0 minutes 7.922 seconds)

Gallery generated by Sphinx-Gallery