Skip to content

Commit aa04769

Browse files
committed
Add init function to anim decay example
Ensures that the plot is cleared before restarting the animation
1 parent 2b77d8e commit aa04769

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

examples/animation/animate_decay.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ def data_gen(t=0):
1010
t += 0.1
1111
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
1212

13+
def init():
14+
ax.set_ylim(-1.1, 1.1)
15+
ax.set_xlim(0, 10)
16+
del xdata[:]
17+
del ydata[:]
18+
line.set_data(xdata,ydata)
19+
return line,
20+
1321
fig, ax = plt.subplots()
1422
line, = ax.plot([], [], lw=2)
15-
ax.set_ylim(-1.1, 1.1)
16-
ax.set_xlim(0, 5)
1723
ax.grid()
1824
xdata, ydata = [], []
1925

@@ -33,5 +39,5 @@ def run(data):
3339
return line,
3440

3541
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
36-
repeat=False)
42+
repeat=False, init_func=init)
3743
plt.show()

0 commit comments

Comments
 (0)