Skip to content

Simplify the pyplot animation demo. #9852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions examples/animation/animation_demo.py
Original file line number Diff line number Diff line change
@@ -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)