◐ Shell
clean mode source ↗

ENH: Add paused kwarg to Animation and is_running() to TimerBase by KomalDeep355 · Pull Request #31924 · matplotlib/matplotlib

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