Animation¶
Animation
¶
Animation(
render: Callable[..., Figure],
frames: Union[int, Iterable],
*,
fps: float = 20.0,
repeat: bool = True
)
A sequence of figures encoded as an animated image.
Parameters¶
render:
Called once per frame as render(value); must return a
pyplotrs.Figure.
frames:
Either an int (the callback receives 0 .. frames-1) or an
iterable of values passed to the callback in order.
fps:
Frames per second (default 20).
repeat:
Loop forever (default) or play through once.
Source code in python/pyplotrs/animation.py
to_bytes
¶
Render every frame and return the encoded animation.
format is "gif" (256-color, plays anywhere) or "apng"
(full 8-bit color); a leading dot and any capitalization are accepted,
so a file extension can be handed straight through. dpi sets the
raster resolution and fps overrides the construction-time frame
rate, both as in save.
This is the primitive save is
built on. Reach for it when the destination is not a path - an HTTP
response, a zip member, a BytesIO - and use save otherwise,
since it does not hold the encoded animation and the file at once.
Source code in python/pyplotrs/animation.py
save
¶
save(
path: Union[str, PathLike],
*,
dpi: float = 100.0,
fps: Optional[float] = None,
format: Optional[str] = None
) -> None
Render every frame and encode to path.
The format is taken from the extension: .gif (256-color, broadly
viewable) or .apng / .png (full-color). dpi sets the raster
resolution; fps overrides the construction-time frame rate;
format overrides the extension, for a path that does not carry one.
render is called once per frame per save, so writing two formats
from one Animation builds every figure twice - and a callback that
draws on random numbers would not even build the same one twice. Encode
once with to_bytes and write
the bytes yourself when that matters.
Source code in python/pyplotrs/animation.py
animate
¶
animate(
render: Callable[..., Figure],
frames: Union[int, Iterable],
*,
fps: float = 20.0,
repeat: bool = True
) -> Animation
Convenience constructor for Animation (see its docstring).