smpl_animation.animation.FigAnimation¶
- class smpl_animation.animation.FigAnimation(figs=None, frames=None, init=None, update=None, *args, **kwargs)[source]¶
Bases:
FuncAnimation
Methods
__init__
([figs, frames, init, update])Return a new sequence of frame information.
Return a new sequence of saved/cached frame information.
pause
()Pause the animation.
resume
()Resume the animation.
save
(filename[, writer, fps, dpi, codec, ...])Save the animation as a movie file by drawing every frame.
to_html5_video
([embed_limit])Convert the animation to an HTML5
<video>
tag.to_jshtml
([fps, embed_frames, default_mode])Generate HTML representation of the animation.
widget_gif
()- new_frame_seq()¶
Return a new sequence of frame information.
- new_saved_frame_seq()¶
Return a new sequence of saved/cached frame information.
- pause()¶
Pause the animation.
- resume()¶
Resume the animation.
- save(filename, writer=None, fps=None, dpi=None, codec=None, bitrate=None, extra_args=None, metadata=None, extra_anim=None, savefig_kwargs=None, *, progress_callback=None)¶
Save the animation as a movie file by drawing every frame.
Parameters¶
- filenamestr
The output filename, e.g.,
mymovie.mp4
.- writerMovieWriter or str, default: :rc:`animation.writer`
A MovieWriter instance to use or a key that identifies a class to use, such as ‘ffmpeg’.
- fpsint, optional
Movie frame rate (per second). If not set, the frame rate from the animation’s frame interval.
- dpifloat, default: :rc:`savefig.dpi`
Controls the dots per inch for the movie frames. Together with the figure’s size in inches, this controls the size of the movie.
- codecstr, default: :rc:`animation.codec`.
The video codec to use. Not all codecs are supported by a given MovieWriter.
- bitrateint, default: :rc:`animation.bitrate`
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 :rc:`animation.[name-of-encoder]_args` for the builtin writers.
- metadatadict[str, str], default: {}
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.
- extra_animlist, default: []
Additional Animation objects that should be included in the saved movie file. These need to be from the same matplotlib.figure.Figure instance. Also, animation frames will just be simply combined, so there should be a 1:1 correspondence between the frames from the different animations.
- savefig_kwargsdict, default: {}
Keyword arguments passed to each ~.Figure.savefig call used to save the individual frames.
- progress_callbackfunction, optional
A callback function that will be called for every frame to notify the saving progress. It must have the signature
def func(current_frame: int, total_frames: int) -> Any
where current_frame is the current frame number and total_frames is the total number of frames to be saved. total_frames is set to None, if the total number of frames can not be determined. Return values may exist but are ignored.
Example code to write the progress to stdout:
progress_callback = lambda i, n: print(f'Saving frame {i} of {n}')
Notes¶
fps, codec, bitrate, extra_args and metadata are used to construct a .MovieWriter instance and can only be passed if writer is a string. If they are passed as non-None and writer is a .MovieWriter, a RuntimeError will be raised.
- to_html5_video(embed_limit=None)¶
Convert the animation to an HTML5
<video>
tag.This saves the animation as an h264 video, encoded in base64 directly into the HTML5 video tag. This respects :rc:`animation.writer` and :rc:`animation.bitrate`. This also makes use of the
interval
to control the speed, and uses therepeat
parameter to decide whether to loop.Parameters¶
- embed_limitfloat, optional
Limit, in MB, of the returned animation. No animation is created if the limit is exceeded. Defaults to :rc:`animation.embed_limit` = 20.0.
Returns¶
- str
An HTML5 video tag with the animation embedded as base64 encoded h264 video. If the embed_limit is exceeded, this returns the string “Video too large to embed.”
- to_jshtml(fps=None, embed_frames=True, default_mode=None)¶
Generate HTML representation of the animation.
Parameters¶
- fpsint, optional
Movie frame rate (per second). If not set, the frame rate from the animation’s frame interval.
embed_frames : bool, optional default_mode : str, optional
What to do when the animation ends. Must be one of
{'loop', 'once', 'reflect'}
. Defaults to'loop'
ifself.repeat
is True, otherwise'once'
.