{{ message }}
ENH: Add paused kwarg to Animation and is_running() to TimerBase#31924
Open
KomalDeep355 wants to merge 5 commits into
Open
ENH: Add paused kwarg to Animation and is_running() to TimerBase#31924KomalDeep355 wants to merge 5 commits into
KomalDeep355 wants to merge 5 commits into
Conversation
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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