-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathanimation_demo.py
More file actions
30 lines (22 loc) · 770 Bytes
/
animation_demo.py
File metadata and controls
30 lines (22 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
================
pyplot animation
================
Generating an animation by calling `~.pyplot.pause` between plotting commands.
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.
Output generated via `matplotlib.animation.Animation.to_jshtml`.
"""
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, img in enumerate(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)