ENH: Add paused kwarg to Animation and is_running() to TimerBase#31924
ENH: Add paused kwarg to Animation and is_running() to TimerBase#31924KomalDeep355 wants to merge 5 commits into
Conversation
|
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. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Fixed the pre-commit failures (RST formatting and line endings in the release 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! |
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
pausedkeyword argument to 'Animation.init' that, when True, prevents the event source from auto-starting. It also adds an 'is_running()' method to 'TimerBase' so userscan 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:
##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