Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc449ee4

Browse files
authored
Merge pull request#16225 from anntzer/animex
Cleanup animation examples.
2 parentsf857586 +d5e8182 commitc449ee4

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+
importitertools
12+
1113
importnumpyasnp
1214
importmatplotlib.pyplotasplt
1315
importmatplotlib.animationasanimation
1416

1517

1618
defdata_gen():
17-
forcntinrange(1000):
19+
forcntinitertools.count():
1820
t=cnt/10
1921
yieldt,np.sin(2*np.pi*t)*np.exp(-t/10.)
2022

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

4850
returnline,
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-
definit(self):
42-
self.success=0
43-
self.line.set_data([], [])
44-
returnself.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-
ifi==0:
50-
returnself.init()
5144

5245
# Choose success based on exceed a threshold with a uniform pick
5346
ifnp.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-
definit():
83-
line.set_data([], [])
84-
time_text.set_text('')
85-
returnline,time_text
86-
87-
8882
defanimate(i):
8983
thisx= [0,x1[i],x2[i]]
9084
thisy= [0,y1[i],y2[i]]
@@ -94,6 +88,6 @@ def animate(i):
9488
returnline,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-
definit():# only required for blitting to give a clean slate.
19-
line.set_ydata([np.nan]*len(x))
20-
returnline,
21-
22-
2318
defanimate(i):
2419
line.set_ydata(np.sin(x+i/100))# update the data.
2520
returnline,
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)

[8]ページ先頭

©2009-2025 Movatter.jp