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

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 5, 2020

  • Simplify the implementation of repeat_delay: instead of switching
    callbacks back and forth, just set the timer interval at each
    iteration to either the normal delay or the end-of-loop delay.

  • Fix support for repeat_delay when frames is an iterable: the
    previous implementation handled looping in iter_frames and therefore
    _step never saw the end of the iterable. Instead, just iterate
    through frames once in iter_frames, but still tee the iterable
    so that _step can take care of repeating the animation.

Can be checked with

import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()
line, = ax.plot(range(10))

def animate(i):
    line.set_ydata(range(i, i + 10))  # update the data.
    return line,

ani = animation.FuncAnimation(
    fig, animate, frames=range(5), interval=1000, repeat_delay=2000, blit=True, save_count=50)
plt.show()

Previously repeat_delay would not be applied (this was likely intro'ed by
#14068, so this PR could be considered as a bugfix, hence the milestoning).

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

- Simplify the implementation of `repeat_delay`: instead of switching
  callbacks back and forth, just set the timer interval at each
  iteration to either the normal delay or the end-of-loop delay.

- Fix support for `repeat_delay` when `frames` is an iterable: the
  previous implementation handled looping in `iter_frames` and therefore
  `_step` never saw the end of the iterable.  Instead, just iterate
  through `frames` once in `iter_frames`, but still `tee` the iterable
  so that `_step` can take care of repeating the animation.

Can be checked with
```python
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()
line, = ax.plot(range(10))

def animate(i):
    line.set_ydata(range(i, i + 10))  # update the data.
    return line,

ani = animation.FuncAnimation(
    fig, animate, frames=range(5), interval=1000, repeat_delay=2000, blit=True, save_count=50)
plt.show()
```
Previously repeat_delay would not be applied.
@anntzer anntzer added this to the v3.3.3 milestone Nov 5, 2020
@QuLogic
Copy link
Member

QuLogic commented Nov 6, 2020

That PR was in 3.2.0, so this is not a bugfix for 3.3 specifically?

@anntzer
Copy link
Contributor Author

anntzer commented Nov 6, 2020

No, I don't really mind where this gets milestoned in fact, I was just pointing out it's a recentish breakage.

@QuLogic QuLogic modified the milestones: v3.3.3, v3.4.0 Nov 10, 2020
@QuLogic QuLogic merged commit a129e6e into matplotlib:master Nov 10, 2020
@QuLogic
Copy link
Member

QuLogic commented Nov 10, 2020

Alright, I'm not entirely sure it should be backported then. Let's leave it off for now.

@anntzer anntzer deleted the repeat_delay branch November 10, 2020 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants