You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Version 2.0.0b1.post7580.dev0+ge487118
matplotlib
Fork me on GitHub

Related Topics

This Page

pyplot animationΒΆ

Generating an animation by calling pause between plotting commands.

The method shown here is only suitable for simple, low-performance use. For more demanding applications, look at the animation module and the examples that use it.

Note that calling time.sleep instead of pause would not work.

../../_images/sphx_glr_animation_demo_001.png
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(19680801)
data = np.random.random((50, 50, 50))

fig, ax = plt.subplots()

for i in range(len(data)):
    ax.cla()
    ax.imshow(data[i])
    ax.set_title("frame {}".format(i))
    # Note that using time.sleep does *not* work here!
    plt.pause(0.1)

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

Gallery generated by Sphinx-Gallery