Skip to content

DOC: Fix resizing of animation examples #27006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion galleries/examples/animation/bayes_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def __init__(self, ax, prob=0.5):
# which the plotted distribution should converge.
self.ax.axvline(prob, linestyle='--', color='black')

def start(self):
# Used for the *init_func* parameter of FuncAnimation; this is called when
# initializing the animation, and also after resizing the figure.
return self.line,

def __call__(self, i):
# This way the plot can continuously run and we just keep
# watching new realizations of the process
Expand All @@ -62,5 +67,5 @@ def __call__(self, i):

fig, ax = plt.subplots()
ud = UpdateDist(ax, prob=0.7)
anim = FuncAnimation(fig, ud, frames=100, interval=100, blit=True)
anim = FuncAnimation(fig, ud, init_func=ud.start, frames=100, interval=100, blit=True)
plt.show()
11 changes: 2 additions & 9 deletions galleries/examples/animation/double_pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
Output generated via `matplotlib.animation.Animation.to_jshtml`.
"""

from collections import deque

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


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

if i == 0:
history_x.clear()
history_y.clear()

history_x.appendleft(thisx[2])
history_y.appendleft(thisy[2])
history_x = x2[:i]
history_y = y2[:i]

line.set_data(thisx, thisy)
trace.set_data(history_x, history_y)
Expand Down
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