1""" 2================ 3pyplot animation 4================ 5 6Generating an animation by calling `~.pyplot.pause` between plotting commands. 7 8The method shown here is only suitable for simple, low-performance use. For 9more demanding applications, look at the :mod:`animation` module and the 10examples that use it. 11 12Note that calling `time.sleep` instead of `~.pyplot.pause` would *not* work. 13""" 14 15import matplotlib.pyplot as plt 16import numpy as np 17 18np.random.seed(19680801) 19data = np.random.random((50, 50, 50)) 20 21fig, ax = plt.subplots() 22 23for i in range(len(data)): 24 ax.cla() 25 ax.imshow(data[i]) 26 ax.set_title("frame {}".format(i)) 27 # Note that using time.sleep does *not* work here! 28 plt.pause(0.1) 29