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

Skip to content

Simplify repeat_delay and fix support for it when using iterable frames. #18901

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
Nov 10, 2020
Merged
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
23 changes: 4 additions & 19 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,27 +1433,12 @@ def _step(self, *args):
if not still_going and self.repeat:
self._init_draw()
self.frame_seq = self.new_frame_seq()
self.event_source.remove_callback(self._step)
self.event_source.add_callback(self._loop_delay)
self.event_source.interval = self._repeat_delay
return True
else:
self.event_source.interval = self._interval
return still_going

def _stop(self, *args):
# If we stop in the middle of a loop delay (which is relatively likely
# given the potential pause here), remove the loop_delay callback as
# well.
self.event_source.remove_callback(self._loop_delay)
super()._stop()

def _loop_delay(self, *args):
# Reset the interval and change callbacks after the delay.
self.event_source.remove_callback(self._loop_delay)
self.event_source.interval = self._interval
self.event_source.add_callback(self._step)
Animation._step(self)


class ArtistAnimation(TimedAnimation):
"""
Expand Down Expand Up @@ -1633,10 +1618,10 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
self._iter_gen = frames
elif np.iterable(frames):
if kwargs.get('repeat', True):
self._tee_from = frames
def iter_frames(frames=frames):
while True:
this, frames = itertools.tee(frames, 2)
yield from this
this, self._tee_from = itertools.tee(self._tee_from, 2)
yield from this
self._iter_gen = iter_frames
else:
self._iter_gen = lambda: iter(frames)
Expand Down