Note
Go to the endto download the full example code.
pyplot animation#
Generating an animation by callingpause between plotting commands.
The method shown here is only suitable for simple, low-performance use. Formore demanding applications, look at theanimation module and theexamples that use it.
Note that callingtime.sleep instead ofpause wouldnot work.
Output generated viamatplotlib.animation.Animation.to_jshtml.

importmatplotlib.pyplotaspltimportnumpyasnpnp.random.seed(19680801)data=np.random.random((50,50,50))fig,ax=plt.subplots()fori,imginenumerate(data):ax.clear()ax.imshow(img)ax.set_title(f"frame{i}")# Note that using time.sleep does *not* work here!plt.pause(0.1)
Total running time of the script: (0 minutes 8.150 seconds)