Skip to content

Commit b2dbaf5

Browse files
authored
Merge pull request #27009 from meeseeksmachine/auto-backport-of-pr-27006-on-v3.8.x
Backport PR #27006 on branch v3.8.x (DOC: Fix resizing of animation examples)
2 parents f35b744 + 057ef0d commit b2dbaf5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

galleries/examples/animation/bayes_update.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def __init__(self, ax, prob=0.5):
4141
# which the plotted distribution should converge.
4242
self.ax.axvline(prob, linestyle='--', color='black')
4343

44+
def start(self):
45+
# Used for the *init_func* parameter of FuncAnimation; this is called when
46+
# initializing the animation, and also after resizing the figure.
47+
return self.line,
48+
4449
def __call__(self, i):
4550
# This way the plot can continuously run and we just keep
4651
# watching new realizations of the process
@@ -62,5 +67,5 @@ def __call__(self, i):
6267

6368
fig, ax = plt.subplots()
6469
ud = UpdateDist(ax, prob=0.7)
65-
anim = FuncAnimation(fig, ud, frames=100, interval=100, blit=True)
70+
anim = FuncAnimation(fig, ud, init_func=ud.start, frames=100, interval=100, blit=True)
6671
plt.show()

galleries/examples/animation/double_pendulum.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
Output generated via `matplotlib.animation.Animation.to_jshtml`.
1212
"""
1313

14-
from collections import deque
15-
1614
import matplotlib.pyplot as plt
1715
import numpy as np
1816
from numpy import cos, sin
@@ -92,19 +90,14 @@ def derivs(t, state):
9290
trace, = ax.plot([], [], '.-', lw=1, ms=2)
9391
time_template = 'time = %.1fs'
9492
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)
95-
history_x, history_y = deque(maxlen=history_len), deque(maxlen=history_len)
9693

9794

9895
def animate(i):
9996
thisx = [0, x1[i], x2[i]]
10097
thisy = [0, y1[i], y2[i]]
10198

102-
if i == 0:
103-
history_x.clear()
104-
history_y.clear()
105-
106-
history_x.appendleft(thisx[2])
107-
history_y.appendleft(thisy[2])
99+
history_x = x2[:i]
100+
history_y = y2[:i]
108101

109102
line.set_data(thisx, thisy)
110103
trace.set_data(history_x, history_y)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy