matplotlib.animation.FuncAnimation

class matplotlib.animation.FuncAnimation(fig, func, frames=None, init_func=None, fargs=None, save_count=None, *, cache_frame_data=True, **kwargs) [source]

Makes an animation by repeatedly calling a function func.

Parameters:
figFigure

The figure object that is used to get draw, resize, and any other needed events.

funccallable

The function to call at each frame. The first argument will be the next value in frames. Any additional positional arguments can be supplied via the fargs parameter.

The required signature is:

def func(frame, *fargs) -> iterable_of_artists

If blit == True, func must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if blit == False and may be omitted in that case.

framesiterable, int, generator function, or None, optional

Source of data to pass func and each frame of the animation

  • If an iterable, then simply use the values provided. If the iterable has a length, it will override the save_count kwarg.
  • If an integer, then equivalent to passing range(frames)
  • If a generator function, then must have the signature:

    def gen_function() -> obj
    
  • If None, then equivalent to passing itertools.count.

In all of these cases, the values in frames is simply passed through to the user-supplied func and thus can be of any type.

init_funccallable, optional

A function used to draw a clear frame. If not given, the results of drawing from the first item in the frames sequence will be used. This function will be called once before the first frame.

The required signature is:

def init_func() -> iterable_of_artists

If blit == True, init_func must return an iterable of artists to be re-drawn. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if blit == False and may be omitted in that case.

fargstuple or None, optional

Additional arguments to pass to each call to func.

save_countint, default: 100

Fallback for the number of values from frames to cache. This is only used if the number of frames cannot be inferred from frames, i.e. when it's an iterator without length or a generator.

intervalnumber, optional

Delay between frames in milliseconds. Defaults to 200.

repeat_delaynumber, optional

If the animation in repeated, adds a delay in milliseconds before repeating the animation. Defaults to None.

repeatbool, optional

Controls whether the animation should repeat when the sequence of frames is completed. Defaults to True.

blitbool, optional

Controls whether blitting is used to optimize drawing. Note: when using blitting any animated artists will be drawn according to their zorder. However, they will be drawn on top of any previous artists, regardless of their zorder. Defaults to False.

cache_frame_databool, optional

Controls whether frame data is cached. Defaults to True. Disabling cache might be helpful when frames contain large objects.

__init__(self, fig, func, frames=None, init_func=None, fargs=None, save_count=None, *, cache_frame_data=True, **kwargs) [source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, fig, func[, frames, ...]) Initialize self.
new_frame_seq(self) Return a new sequence of frame information.
new_saved_frame_seq(self) Return a new sequence of saved/cached frame information.
save(self, filename[, writer, fps, dpi, ...]) Save the animation as a movie file by drawing every frame.
to_html5_video(self[, embed_limit]) Convert the animation to an HTML5 <video> tag.
to_jshtml(self[, fps, embed_frames, ...]) Generate HTML representation of the animation
new_frame_seq(self) [source]

Return a new sequence of frame information.

new_saved_frame_seq(self) [source]

Return a new sequence of saved/cached frame information.

© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.2.2/api/_as_gen/matplotlib.animation.FuncAnimation.html