8000 Merge pull request #16225 from anntzer/animex · matplotlib/matplotlib@c449ee4 · GitHub
[go: up one dir, main page]

Skip to content

Commit c449ee4

Browse files
authored
Merge pull request #16225 from anntzer/animex
Cleanup animation examples.
2 parents f857586 + d5e8182 commit c449ee4

File tree

4 files changed

+8
-26
lines changed

4 files changed

+8
-26
lines changed

examples/animation/animate_decay.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
- changing axes limits during an animation.
99
"""
1010

11+
import itertools
12+
1113
import numpy as np
1214
import matplotlib.pyplot as plt
1315
import matplotlib.animation as animation
1416

1517

1618
def data_gen():
17-
for cnt in range(1000):
19+
for cnt in itertools.count():
1820
t = cnt / 10
1921
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
2022

@@ -47,6 +49,5 @@ def run(data):
4749

4850
return line,
4951

50-
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
51-
repeat=False, init_func=init)
52+
ani = animation.FuncAnimation(fig, run, data_gen, interval=10, init_func=init)
5253
plt.show()

examples/animation/bayes_update.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,9 @@ def __init__(self, ax, prob=0.5):
3838
# which the plotted distribution should converge.
3939
self.ax.axvline(prob, linestyle='--', color='black')
4040

41-
def init(self):
42-
self.success = 0
43-
self.line.set_data([], [])
44-
return self.line,
45-
4641
def __call__(self, i):
4742
# This way the plot can continuously run and we just keep
4843
# watching new realizations of the process
49-
if i == 0:
50-
return self.init()
5144

5245
# Choose success based on exceed a threshold with a uniform pick
5346
if np.random.rand(1,) < self.prob:
@@ -62,6 +55,5 @@ def __call__(self, i):
6255

6356
fig, ax = plt.subplots()
6457
ud = UpdateDist(ax, prob=0.7)
65-
anim = FuncAnimation(fig, ud, frames=np.arange(100), init_func=ud.init,
66-
interval=100, blit=True)
58+
anim = FuncAnimation(fig, ud, frames=100, interval=100, blit=True)
6759
plt.show()

examples/animation/double_pendulum_sgskip.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ def derivs(state, t):
7979
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)
8080

8181

82-
def init():
83-
line.set_data([], [])
84-
time_text.set_text('')
85-
return line, time_text
86-
87-
8882
def animate(i):
8983
thisx = [0, x1[i], x2[i]]
9084
thisy = [0, y1[i], y2[i]]
@@ -94,6 +88,6 @@ def animate(i):
9488
return line, time_text
9589

9690

97-
ani = animation.FuncAnimation(fig, animate, range(1, len(y)),
98-
interval=dt*1000, blit=True, init_func=init)
91+
ani = animation.FuncAnimation(
92+
fig, animate, len(y), interval=dt*1000, blit=True)
9993
plt.show()

examples/animation/simple_anim.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@
1515
line, = ax.plot(x, np.sin(x))
1616

1717

18-
def init(): # only required for blitting to give a clean slate.
19-
line.set_ydata([np.nan] * len(x))
20-
return line,
21-
22-
2318
def animate(i):
2419
line.set_ydata(np.sin(x + i / 100)) # update the data.
2520
return line,
2621

2722

2823
ani = animation.FuncAnimation(
29-
fig, animate, init_func=init, interval=2, blit=True, save_count=50)
24+
fig, animate, interval=2, blit=True, save_count=50)
3025

3126
# To save the animation, use e.g.
3227
#

0 commit comments

Comments
 (0)
0