matplotlib.animation.MovieWriter

class matplotlib.animation.MovieWriter(fps=5, codec=None, bitrate=None, extra_args=None, metadata=None)[source]

Base class for writing movies.

This is a base class for MovieWriter subclasses that write a movie frame data to a pipe. You cannot instantiate this class directly. See examples for how to use its subclasses.

Attributes:
frame_formatstr

The format used in writing frame data, defaults to 'rgba'.

figFigure

The figure to capture data from. This must be provided by the sub-classes.

Parameters:
fpsint, default: 5

Movie frame rate (per second).

codecstr or None, default: rcParams["animation.codec"] (default: 'h264')

The codec to use.

bitrateint, default: rcParams["animation.bitrate"] (default: -1)

The bitrate of the movie, in kilobits per second. Higher values means higher quality movies, but increase the file size. A value of -1 lets the underlying movie encoder select the bitrate.

extra_argslist of str or None, optional

Extra command-line arguments passed to the underlying movie encoder. The default, None, means to use rcParams["animation.[name-of-encoder]_args"] for the builtin writers.

metadataDict[str, str], default: {}

A dictionary of keys and values for metadata to include in the output file. Some keys that may be of use include: title, artist, genre, subject, copyright, srcform, comment.

__init__(fps=5, codec=None, bitrate=None, extra_args=None, metadata=None)[source]
Parameters:
fpsint, default: 5

Movie frame rate (per second).

codecstr or None, default: rcParams["animation.codec"] (default: 'h264')

The codec to use.

bitrateint, default: rcParams["animation.bitrate"] (default: -1)

The bitrate of the movie, in kilobits per second. Higher values means higher quality movies, but increase the file size. A value of -1 lets the underlying movie encoder select the bitrate.

extra_argslist of str or None, optional

Extra command-line arguments passed to the underlying movie encoder. The default, None, means to use rcParams["animation.[name-of-encoder]_args"] for the builtin writers.

metadataDict[str, str], default: {}

A dictionary of keys and values for metadata to include in the output file. Some keys that may be of use include: title, artist, genre, subject, copyright, srcform, comment.

Methods

__init__([fps, codec, bitrate, extra_args, ...])
Parameters:
bin_path() Return the binary path to the commandline tool used by a specific subclass.
cleanup() Clean-up and collect the process used to write the movie file.
finish() Finish any processing for writing the movie.
grab_frame(**savefig_kwargs) Grab the image information from the figure and save as a movie frame.
isAvailable() Return whether a MovieWriter subclass is actually available.
saving(fig, outfile, dpi, *args, **kwargs) Context manager to facilitate writing the movie file.
setup(fig, outfile[, dpi]) Setup for writing the movie file.

Attributes

args_key
exec_key
frame_size A tuple (width, height) in pixels of a movie frame.
property args_key
classmethod bin_path()[source]

Return the binary path to the commandline tool used by a specific subclass. This is a class method so that the tool can be looked for before making a particular MovieWriter subclass available.

cleanup()[source]

Clean-up and collect the process used to write the movie file.

property exec_key
finish()[source]

Finish any processing for writing the movie.

grab_frame(**savefig_kwargs)[source]

Grab the image information from the figure and save as a movie frame.

All keyword arguments in savefig_kwargs are passed on to the savefig call that saves the figure.

classmethod isAvailable()[source]

Return whether a MovieWriter subclass is actually available.

setup(fig, outfile, dpi=None)[source]

Setup for writing the movie file.

Parameters:
figFigure

The figure object that contains the information for frames.

outfilestr

The filename of the resulting movie file.

dpifloat, default: fig.dpi

The DPI (or resolution) for the file. This controls the size in pixels of the resulting movie file.