Skip to content

Deprecate truncating saved unsized anims to 100 frames. #10301

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 1 commit into from
Jan 28, 2018
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/simple_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
26 changes: 22 additions & 4 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down