diff --git a/examples/animation/dynamic_image.py b/examples/animation/dynamic_image.py index 247bbc031ad9..fd07c36e7bb4 100644 --- a/examples/animation/dynamic_image.py +++ b/examples/animation/dynamic_image.py @@ -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): diff --git a/examples/animation/dynamic_image2.py b/examples/animation/dynamic_image2.py index c4a29b3d00aa..b15723081020 100644 --- a/examples/animation/dynamic_image2.py +++ b/examples/animation/dynamic_image2.py @@ -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, diff --git a/examples/animation/histogram.py b/examples/animation/histogram.py index a8c4c13b8cf4..1ca8c35ac5e5 100644 --- a/examples/animation/histogram.py +++ b/examples/animation/histogram.py @@ -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() diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index b3c946225ec5..6b1e05870196 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -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) @@ -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: @@ -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): ''' @@ -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. @@ -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)