mpl-animators

raw JSON →
1.2.4 verified Fri May 01 auth: no python

An interactive animation framework for matplotlib providing convenient classes to create animations with sliders and buttons. Current version 1.2.4, requires Python >=3.10. Released on PyPI with periodic updates.

pip install mpl-animators
error ImportError: cannot import name 'FuncAnimation' from 'mpl_animators'
cause Incorrect spelling or version mismatch. The correct import is from mpl_animators import FuncAnimation (note underscore in module name).
fix
Use 'from mpl_animators import FuncAnimation' (no hyphen, no capital A).
error AttributeError: module 'mpl_animators' has no attribute 'FuncAnimation'
cause Installed a very old version or wrong package. mpl-animators may not be installed or is a different package.
fix
Run 'pip install mpl-animators==1.2.4' and then import as shown.
gotcha The class 'FuncAnimation' in mpl_animators shadows matplotlib's FuncAnimation. If you import both, the last import wins and may break code expecting the standard behavior.
fix Use explicit import aliasing: from mpl_animators import FuncAnimation as InteractiveAnimation
gotcha The 'blit' parameter is enabled by default in mpl_animators.FuncAnimation, which can cause issues with artists that are not explicitly returned in the update function. For simple animations, set blit=False to avoid invisible updates.
fix Set blit=False in FuncAnimation constructor if you experience blank frames.
gotcha The library requires matplotlib backend that supports interactive widgets. If using a non-interactive backend (e.g., 'Agg'), the sliders and buttons will not appear.
fix Ensure interactive backend: import matplotlib; matplotlib.use('TkAgg') or use %matplotlib notebook in Jupyter.

Minimal interactive animation with a slider that controls the frame.

import matplotlib.pyplot as plt
from mpl_animators import FuncAnimation

fig, ax = plt.subplots()
x = [0, 1, 2]
y = [0, 1, 4]
ln, = ax.plot([], [], 'ro')

def update(frame):
    ln.set_data(x[:frame], y[:frame])
    return ln,

ani = FuncAnimation(fig, update, frames=3, interval=1000, repeat=False, blit=True)
plt.show()