FuncAnimation#
- class FuncAnimation(fig, func, frames=None, init_func=None, fargs=None, save_count=None, *, blit=True, **kwargs)[source]#
Bases:
_FastSaveMixin,FuncAnimationA faster drop-in replacement for
matplotlib.animation.FuncAnimation.The signature matches Matplotlib’s, with two differences:
blitdefaults toTrueinstead ofFalse, andfreeze_layoutis added. Saving renders frames directly into the Agg buffer instead of callingsavefigonce per frame, which removes the per-frame PNG round-trip and the repeated UltraPlot tight-layout pass.- Parameters:
fig (
Figure) – The figure to animate.func (
callable()) – The update function, called asfunc(frame, *fargs). It should return an iterable of the artists it modified. This is required whenblitisTrue, and lets the fast path skip untouched artists.frames (
int,iterable,generator, orNone, optional) – Source of frame data, as in Matplotlib.init_func (
callable(), optional) – Function drawing the clear frame. Should return the animated artists.fargs (
tuple, optional) – Extra positional arguments forfuncandinit_func.save_count (
int, optional) – Number of frames to cache from a generator.blit (
bool, default:True) – Whether to redraw only the artists returned byfunc. This is the main source of the speedup, but it means changes to artists that are not returned, such as titles or tick labels, will not show up. PassFalseto redraw the whole figure each frame, which is still faster than Matplotlib because the layout solver is frozen.cache_frame_data (
bool, default:True) – Whether to cache frame data, as in Matplotlib.**kwargs – Passed to
matplotlib.animation.TimedAnimation, e.g.interval,repeat, andrepeat_delay.
Examples
>>> import ultraplot as uplt >>> import numpy as np >>> fig, ax = uplt.subplots() >>> x = np.linspace(0, 2 * np.pi, 200) >>> (line,) = ax.plot(x, np.sin(x)) >>> def update(frame): ... line.set_ydata(np.sin(x + frame / 10)) ... return (line,) ... >>> ani = uplt.FuncAnimation(fig, update, frames=100) >>> ani.save('waves.mp4')