Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f68f9a1

Browse files
authored
Merge pull request #10301 from anntzer/dont-truncate-anims
Deprecate truncating saved unsized anims to 100 frames.
2 parents 2594eb6 + 15c6d59 commit f68f9a1

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

examples/animation/simple_anim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def animate(i):
2626

2727

2828
ani = animation.FuncAnimation(
29-
fig, animate, init_func=init, interval=2, blit=True)
29+
fig, animate, init_func=init, interval=2, blit=True, save_count=50)
3030

3131
# To save the animation, use e.g.
3232
#

lib/matplotlib/animation.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838

3939
from matplotlib._animation_data import (DISPLAY_TEMPLATE, INCLUDED_FRAMES,
4040
JS_INCLUDE)
41-
from matplotlib.cbook import iterable, deprecated
4241
from matplotlib.compat import subprocess
43-
from matplotlib import rcParams, rcParamsDefault, rc_context
42+
from matplotlib import cbook, rcParams, rcParamsDefault, rc_context
4443

4544
if six.PY2:
4645
from base64 import encodestring as encodebytes
@@ -1679,7 +1678,7 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
16791678
self._iter_gen = itertools.count
16801679
elif callable(frames):
16811680
self._iter_gen = frames
1682-
elif iterable(frames):
1681+
elif cbook.iterable(frames):
16831682
self._iter_gen = lambda: iter(frames)
16841683
if hasattr(frames, '__len__'):
16851684
self.save_count = len(frames)
@@ -1721,7 +1720,26 @@ def new_saved_frame_seq(self):
17211720
self._old_saved_seq = list(self._save_seq)
17221721
return iter(self._old_saved_seq)
17231722
else:
1724-
return itertools.islice(self.new_frame_seq(), self.save_count)
1723+
if self.save_count is not None:
1724+
return itertools.islice(self.new_frame_seq(), self.save_count)
1725+
1726+
else:
1727+
frame_seq = self.new_frame_seq()
1728+
1729+
def gen():
1730+
try:
1731+
for _ in range(100):
1732+
yield next(frame_seq)
1733+
except StopIteration:
1734+
pass
1735+
else:
1736+
cbook.warn_deprecated(
1737+
"2.2", "FuncAnimation.save has truncated your "
1738+
"animation to 100 frames. In the future, no such "
1739+
"truncation will occur; please pass 'save_count' "
1740+
"accordingly.")
1741+
1742+
return gen()
17251743

17261744
def _init_draw(self):
17271745
# Initialize the drawing either using the given init_func or by

0 commit comments

Comments
 (0)