Matplotlib.animation.FuncAnimation class in Python
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
The matplotlib.animation.FuncAnimation class is used to make animation by repeatedly calling the same function (ie, func).
Syntax: class matplotlib.animation.FuncAnimation(fig, func, frames=None, init_func=None, fargs=None, save_count=None, *, cache_frame_data=True, **kwargs)
- fig: It is the figure object used for drawing, resizing or any other needed events.
Any additional positional arguments can be supplied via the fargs parameter.
- func: It is the callable function that gets called each time. The next value in frames is given through the first argument. Any other additional positional arguments is given via the fargs parameter. If the blit value is equal to True then, func returns an iterable of all artists that are to be modified or created. This data is used by the blitting algorithm to decide which parts of the figure has to be updated. If blit== False then the value returned is unused or omitted.
- frames: It is either an iterable, an integer, a generator function or None. It is an optional argument. It is the data source to be passed to func and every frame of the animation.
- init_func: It is an optional callable function that is used to draw a clear frame.
- fargs: It is an optional parameter that is either a tuple or None, which is an additional arguments that needs to be passed to each call to func.
- save_count: It is an integer that acts as 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.Its default is 100.
- interval: It is an optional integer value that represents the delay between each frame in milliseconds. Its default is 100.
- repeat_delay: It is an optional integer value that adds a delay in milliseconds before repeating the animation. It defaults to None.
- blit: It is an optional boolean argument used to control blitting to optimize drawing.
- cache_frame_data: It is an optional boolean argument used to control cacheing of data. It defaults to True.
Methods of the class:
Methods Description __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