diff --git a/examples/animation/simple_anim.py b/examples/animation/simple_anim.py index 2b0f02849f0f..59552cd1cfa7 100644 --- a/examples/animation/simple_anim.py +++ b/examples/animation/simple_anim.py @@ -26,7 +26,7 @@ def animate(i): ani = animation.FuncAnimation( - fig, animate, init_func=init, interval=2, blit=True) + fig, animate, init_func=init, interval=2, blit=True, save_count=50) # To save the animation, use e.g. # diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index fc291e5152e7..911ee5445947 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -38,9 +38,8 @@ from matplotlib._animation_data import (DISPLAY_TEMPLATE, INCLUDED_FRAMES, JS_INCLUDE) -from matplotlib.cbook import iterable, deprecated from matplotlib.compat import subprocess -from matplotlib import rcParams, rcParamsDefault, rc_context +from matplotlib import cbook, rcParams, rcParamsDefault, rc_context if six.PY2: from base64 import encodestring as encodebytes @@ -1681,7 +1680,7 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None, self._iter_gen = itertools.count elif callable(frames): self._iter_gen = frames - elif iterable(frames): + elif cbook.iterable(frames): self._iter_gen = lambda: iter(frames) if hasattr(frames, '__len__'): self.save_count = len(frames) @@ -1723,7 +1722,26 @@ def new_saved_frame_seq(self): self._old_saved_seq = list(self._save_seq) return iter(self._old_saved_seq) else: - return itertools.islice(self.new_frame_seq(), self.save_count) + if self.save_count is not None: + return itertools.islice(self.new_frame_seq(), self.save_count) + + else: + frame_seq = self.new_frame_seq() + + def gen(): + try: + for _ in range(100): + yield next(frame_seq) + except StopIteration: + pass + else: + cbook.warn_deprecated( + "2.2", "FuncAnimation.save has truncated your " + "animation to 100 frames. In the future, no such " + "truncation will occur; please pass 'save_count' " + "accordingly.") + + return gen() def _init_draw(self): # Initialize the drawing either using the given init_func or by