Skip to content

ENH: Add paused kwarg to Animation and is_running() to TimerBase#31924

Open
KomalDeep355 wants to merge 5 commits into
matplotlib:mainfrom
KomalDeep355:enh/animation-paused-start
Open

ENH: Add paused kwarg to Animation and is_running() to TimerBase#31924
KomalDeep355 wants to merge 5 commits into
matplotlib:mainfrom
KomalDeep355:enh/animation-paused-start

Conversation

@KomalDeep355

Copy link
Copy Markdown

Currently, 'Animation' always starts the event source automatically on the first 'draw_event', which prevents creating an animation in a paused state without touching the private API. This PR adds a paused keyword argument to 'Animation.init' that, when True, prevents the event source from auto-starting. It also adds an 'is_running()' method to 'TimerBase' so users
can query whether the event source is currently running.

Example:

import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

fig, ax = plt.subplots()
line, = ax.plot([], [])

def update(frame):
return line,

ani = FuncAnimation(fig, update, frames=10, paused=True)
print(ani.event_source.is_running()) # False

ani.resume()
print(ani.event_source.is_running()) # True

closes #31883

Testing

Ran the full local test suite ('pytest lib/matplotlib/tests/test_animation.py -v'):
36 passed, 24 skipped, 10 failed. All 10 failures are caused by a pre-existing setuptools_scm DeprecationWarning in my local environment ('release-branch-semver.' version scheme renamed), unrelated to this change — none touch Animation, TimerBase, or any code I modified.

Added two new tests specific to this feature, both passing:

  • test_animation_paused_start
  • test_animation_default_starts

##AI Disclosure
I used Claude (Anthropic) as a coding assistant to help me navigate the codebase, identify the correct files to modify, debug my local Windows build environment, which generated a series of persistent errors (Python version mismatch, missing pybind11 headers, meson/ninja configuration issues, setuptools_scm conflicts) before I could get a working build to run tests and review my code changes for style consistency. All code was written and tested by me; the AI assistant did not generate the PR autonomously. I'm a new contributor to matplotlib and used it primarily to learn the contribution workflow and resolve environment issues specific to my Windows setup.

PR checklist

  • "closes [ENH]: Start Animation in a paused state #31883" is in the body of the PR description
  • new and changed code is tested
  • [N/A] Plotting-related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

@github-actions

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@KomalDeep355

Copy link
Copy Markdown
Author

Fixed the pre-commit failures (RST formatting and line endings in the release
note).

Note: The earlier Ubuntu test failure ('test_indexed_image' in 'test_backend_pdf.py') appears unrelated to this PR — it's caused by a 'DeprecationWarning' from the 'pikepdf' library, not from any code I changed. 10,249 other tests passed, including the two new tests I added for the 'paused' and 'is_running' functionality.

Let me know if anything else needs adjustment!

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.

[ENH]: Start Animation in a paused state

1 participant