Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f0a823

Browse files
committed
Remove dynamic_image, rename dynamic_image2, restore animate_decay.
1 parent b638f92 commit 5f0a823

File tree

4 files changed

+68
-57
lines changed

4 files changed

+68
-57
lines changed

doc/api/animation_api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ Examples
129129
.. toctree::
130130
:maxdepth: 1
131131

132+
../gallery/animation/animate_decay
132133
../gallery/animation/bayes_update
133134
../gallery/animation/double_pendulum_sgskip
134-
../gallery/animation/dynamic_image
135135
../gallery/animation/histogram
136136
../gallery/animation/rain
137137
../gallery/animation/random_walk
@@ -148,7 +148,7 @@ Examples
148148
.. toctree::
149149
:maxdepth: 1
150150

151-
../gallery/animation/dynamic_image2
151+
../gallery/animation/dynamic_image
152152

153153
Writer Classes
154154
==============

examples/animation/animate_decay.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
=====
3+
Decay
4+
=====
5+
6+
This example showcases:
7+
- using a generator to drive an animation,
8+
- changing axes limits during an animation.
9+
"""
10+
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
import matplotlib.animation as animation
14+
15+
16+
def data_gen(t=0):
17+
cnt = 0
18+
while cnt < 1000:
19+
cnt += 1
20+
t += 0.1
21+
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
22+
23+
24+
def init():
25+
ax.set_ylim(-1.1, 1.1)
26+
ax.set_xlim(0, 10)
27+
del xdata[:]
28+
del ydata[:]
29+
line.set_data(xdata, ydata)
30+
return line,
31+
32+
fig, ax = plt.subplots()
33+
line, = ax.plot([], [], lw=2)
34+
ax.grid()
35+
xdata, ydata = [], []
36+
37+
38+
def run(data):
39+
# update the data
40+
t, y = data
41+
xdata.append(t)
42+
ydata.append(y)
43+
xmin, xmax = ax.get_xlim()
44+
45+
if t >= xmax:
46+
ax.set_xlim(xmin, 2*xmax)
47+
ax.figure.canvas.draw()
48+
line.set_data(xdata, ydata)
49+
50+
return line,
51+
52+
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
53+
repeat=False, init_func=init)
54+
plt.show()

examples/animation/dynamic_image.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
==============
3-
Animated image
4-
==============
2+
=================================================
3+
Animated image using a precomputed list of images
4+
=================================================
55
66
"""
77

@@ -17,18 +17,18 @@ def f(x, y):
1717

1818
x = np.linspace(0, 2 * np.pi, 120)
1919
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
20-
21-
im = plt.imshow(f(x, y), animated=True)
22-
23-
24-
def updatefig(*args):
25-
global x, y
20+
# ims is a list of lists, each row is a list of artists to draw in the
21+
# current frame; here we are just animating one artist, the image, in
22+
# each frame
23+
ims = []
24+
for i in range(60):
2625
x += np.pi / 15.
2726
y += np.pi / 20.
28-
im.set_array(f(x, y))
29-
return im,
27+
im = plt.imshow(f(x, y), animated=True)
28+
ims.append([im])
3029

31-
ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
30+
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
31+
repeat_delay=1000)
3232

3333
# To save the animation, use e.g.
3434
#

examples/animation/dynamic_image2.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)