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

Commit78bb82c

Browse files
committed
Merge pull request#4995 from tacaswell/fix_animation
animation fixes
2 parents3122457 +ea96ac8 commit78bb82c

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

‎examples/animation/dynamic_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def f(x, y):
1515
x=np.linspace(0,2*np.pi,120)
1616
y=np.linspace(0,2*np.pi,100).reshape(-1,1)
1717

18-
im=plt.imshow(f(x,y),cmap=plt.get_cmap('jet'))
18+
im=plt.imshow(f(x,y),cmap=plt.get_cmap('viridis'),animated=True)
1919

2020

2121
defupdatefig(*args):

‎examples/animation/dynamic_image2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def f(x, y):
2121
foriinrange(60):
2222
x+=np.pi/15.
2323
y+=np.pi/20.
24-
im=plt.imshow(f(x,y))
24+
im=plt.imshow(f(x,y),cmap='viridis',animated=True)
2525
ims.append([im])
2626

2727
ani=animation.ArtistAnimation(fig,ims,interval=50,blit=True,

‎examples/animation/histogram.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def animate(i):
5858
top=bottom+n
5959
verts[1::5,1]=top
6060
verts[2::5,1]=top
61+
return [patch, ]
6162

62-
ani=animation.FuncAnimation(fig,animate,100,repeat=False)
63+
ani=animation.FuncAnimation(fig,animate,100,repeat=False,blit=True)
6364
plt.show()

‎lib/matplotlib/animation.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,6 @@ def __init__(self, fig, event_source=None, blit=False):
590590
self.frame_seq=self.new_frame_seq()
591591
self.event_source=event_source
592592

593-
# Clear the initial frame
594-
self._init_draw()
595-
596593
# Instead of starting the event source now, we connect to the figure's
597594
# draw_event, so that we only start once the figure has been drawn.
598595
self._first_draw_id=fig.canvas.mpl_connect('draw_event',self._start)
@@ -609,15 +606,18 @@ def _start(self, *args):
609606
Starts interactive animation. Adds the draw frame command to the GUI
610607
handler, calls show to start the event loop.
611608
'''
612-
# On start, we add our callback for stepping the animation and
613-
# actually start the event_source. We also disconnect _start
614-
# from the draw_events
615-
self.event_source.add_callback(self._step)
616-
self._init_draw()
617-
self.event_source.start()
609+
# First disconnect our draw event handler
618610
self._fig.canvas.mpl_disconnect(self._first_draw_id)
619611
self._first_draw_id=None# So we can check on save
620612

613+
# Now do any initial draw
614+
self._init_draw()
615+
616+
# Add our callback for stepping the animation and
617+
# actually start the event_source.
618+
self.event_source.add_callback(self._step)
619+
self.event_source.start()
620+
621621
def_stop(self,*args):
622622
# On stop we disconnect all of our events.
623623
ifself._blit:
@@ -1041,7 +1041,7 @@ def _init_draw(self):
10411041

10421042
# Flush the needed axes
10431043
forfiginfigs:
1044-
fig.canvas.draw()
1044+
fig.canvas.draw_idle()
10451045

10461046
def_pre_draw(self,framedata,blit):
10471047
'''
@@ -1156,8 +1156,9 @@ def _init_draw(self):
11561156
self._draw_frame(next(self.new_frame_seq()))
11571157
else:
11581158
self._drawn_artists=self._init_func()
1159-
forainself._drawn_artists:
1160-
a.set_animated(self._blit)
1159+
ifself._blit:
1160+
forainself._drawn_artists:
1161+
a.set_animated(self._blit)
11611162

11621163
def_draw_frame(self,framedata):
11631164
# Save the data for potential saving of movies.
@@ -1170,5 +1171,6 @@ def _draw_frame(self, framedata):
11701171
# Call the func with framedata and args. If blitting is desired,
11711172
# func needs to return a sequence of any artists that were modified.
11721173
self._drawn_artists=self._func(framedata,*self._args)
1173-
forainself._drawn_artists:
1174-
a.set_animated(self._blit)
1174+
ifself._blit:
1175+
forainself._drawn_artists:
1176+
a.set_animated(self._blit)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp