From c1b6a1c39fdd4661930280c6098de55359c5a078 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 24 Nov 2017 14:15:19 -0800 Subject: [PATCH] Simplify the pyplot animation demo. Focus the pyplot animation demo to just 1) do some simple plotting, 2) call pause(). Yes, it would be more efficient to reuse the same image. But if we are not using the animation module, efficiency is probably the least of our worries. --- examples/animation/animation_demo.py | 39 +++++++++++++--------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/examples/animation/animation_demo.py b/examples/animation/animation_demo.py index 76f7b9804d3e..d83d634b48ec 100644 --- a/examples/animation/animation_demo.py +++ b/examples/animation/animation_demo.py @@ -1,31 +1,28 @@ """ -============== -Animation Demo -============== +================ +pyplot animation +================ -Pyplot animation example. +Generating an animation by calling `~.pyplot.pause` between plotting commands. -The method shown here is only for very simple, low-performance -use. For more demanding applications, look at the animation -module and the examples that use it. +The method shown here is only suitable for simple, low-performance use. For +more demanding applications, look at the :mod:`animation` module and the +examples that use it. + +Note that calling `time.sleep` instead of `~.pyplot.pause` would *not* work. """ import matplotlib.pyplot as plt import numpy as np -x = np.arange(6) -y = np.arange(5) -z = x * y[:, np.newaxis] +np.random.seed(19680801) +data = np.random.random((50, 50, 50)) -for i in range(5): - if i == 0: - p = plt.imshow(z) - fig = plt.gcf() - plt.clim() # clamp the color limits - plt.title("Boring slide show") - else: - z = z + 2 - p.set_data(z) +fig, ax = plt.subplots() - print("step", i) - plt.pause(0.5) +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)