Skip to content

animation fixes #4995

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 8 commits into from
Sep 1, 2015
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
2 changes: 1 addition & 1 deletion examples/animation/dynamic_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def f(x, y):
x = np.linspace(0, 2 * np.pi, 120)
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)

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


def updatefig(*args):
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/dynamic_image2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def f(x, y):
for i in range(60):
x += np.pi / 15.
y += np.pi / 20.
im = plt.imshow(f(x, y))
im = plt.imshow(f(x, y), cmap='viridis', animated=True)
ims.append([im])

ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
Expand Down
3 changes: 2 additions & 1 deletion examples/animation/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def animate(i):
top = bottom + n
verts[1::5, 1] = top
verts[2::5, 1] = top
return [patch, ]

ani = animation.FuncAnimation(fig, animate, 100, repeat=False)
ani = animation.FuncAnimation(fig, animate, 100, repeat=False, blit=True)
plt.show()
30 changes: 16 additions & 14 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,6 @@ def __init__(self, fig, event_source=None, blit=False):
self.frame_seq = self.new_frame_seq()
self.event_source = event_source

# Clear the initial frame
self._init_draw()

# Instead of starting the event source now, we connect to the figure's
# draw_event, so that we only start once the figure has been drawn.
self._first_draw_id = fig.canvas.mpl_connect('draw_event', self._start)
Expand All @@ -609,15 +606,18 @@ def _start(self, *args):
Starts interactive animation. Adds the draw frame command to the GUI
handler, calls show to start the event loop.
'''
# On start, we add our callback for stepping the animation and
# actually start the event_source. We also disconnect _start
# from the draw_events
self.event_source.add_callback(self._step)
self._init_draw()
self.event_source.start()
# First disconnect our draw event handler
self._fig.canvas.mpl_disconnect(self._first_draw_id)
self._first_draw_id = None # So we can check on save

# Now do any initial draw
self._init_draw()

# Add our callback for stepping the animation and
# actually start the event_source.
self.event_source.add_callback(self._step)
self.event_source.start()

def _stop(self, *args):
# On stop we disconnect all of our events.
if self._blit:
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def _init_draw(self):

# Flush the needed axes
for fig in figs:
fig.canvas.draw()
fig.canvas.draw_idle()

def _pre_draw(self, framedata, blit):
'''
Expand Down Expand Up @@ -1156,8 +1156,9 @@ def _init_draw(self):
self._draw_frame(next(self.new_frame_seq()))
else:
self._drawn_artists = self._init_func()
for a in self._drawn_artists:
a.set_animated(self._blit)
if self._blit:
for a in self._drawn_artists:
a.set_animated(self._blit)

def _draw_frame(self, framedata):
# Save the data for potential saving of movies.
Expand All @@ -1170,5 +1171,6 @@ def _draw_frame(self, framedata):
# Call the func with framedata and args. If blitting is desired,
# func needs to return a sequence of any artists that were modified.
self._drawn_artists = self._func(framedata, *self._args)
for a in self._drawn_artists:
a.set_animated(self._blit)
if self._blit:
for a in self._drawn_artists:
a.set_animated(self._blit)