8000 Cleanup animation examples. by anntzer · Pull Request #16225 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Cleanup animation examples. #16225

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
Feb 7, 2020
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: 4 additions & 3 deletions examples/animation/animate_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
- changing axes limits during an animation.
"""

import itertools

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation


def data_gen():
for cnt in range(1000):
for cnt in itertools.count():
t = cnt / 10
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)

Expand Down Expand Up @@ -47,6 +49,5 @@ def run(data):

return line,

ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
repeat=False, init_func=init)
ani = animation.FuncAnimation(fig, run, data_gen, interval=10, init_func=init)
plt.show()
10 changes: 1 addition & 9 deletions examples/animation/bayes_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ def __init__(self, ax, prob=0.5):
# which the plotted distribution should converge.
self.ax.axvline(prob, linestyle='--', color='black')

def init(self):
self.success = 0
self.line.set_data([], [])
return self.line,

def __call__(self, i):
# This way the plot can continuously run and we just keep
# watching new realizations of the process
if i == 0:
return self.init()

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

fig, ax = plt.subplots()
ud = UpdateDist(ax, prob=0.7)
anim = FuncAnimation(fig, ud, frames=np.arange(100), init_func=ud.init,
interval=100, blit=True)
anim = FuncAnimation(fig, ud, frames=100, interval=100, blit=True)
plt.show()
10 changes: 2 additions & 8 deletions examples/animation/double_pendulum_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ def derivs(state, t):
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)


def init():
line.set_data([], [])
time_text.set_text('')
return line, time_text


def animate(i):
thisx = [0, x1[i], x2[i]]
thisy = [0, y1[i], y2[i]]
Expand All @@ -94,6 +88,6 @@ def animate(i):
return line, time_text


ani = animation.FuncAnimation(fig, animate, range(1, len(y)),
interval=dt*1000, blit=True, init_func=init)
ani = animation.FuncAnimation(
fig, animate, len(y), interval=dt*1000, blit=True)
plt.show()
7 changes: 1 addition & 6 deletions examples/animation/simple_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
line, = ax.plot(x, np.sin(x))


def init(): # only required for blitting to give a clean slate.
line.set_ydata([np.nan] * len(x))
return line,


def animate(i):
line.set_ydata(np.sin(x + i / 100)) # update the data.
return line,


ani = animation.FuncAnimation(
fig, animate, init_func=init, interval=2, blit=True, save_count=50)
fig, animate, interval=2, blit=True, save_count=50)

# To save the animation, use e.g.
#
Expand Down
0