cutcutcodec.core.generation.video.matplotlib

Generate a video wih a matplotlib figure.

Classes

GeneratorVideoMatplotlib(func)

Generate a video from matplotlib figure.

Details

class cutcutcodec.core.generation.video.matplotlib.GeneratorVideoMatplotlib(func: Callable[[Fraction], Figure])[source]

Generate a video from matplotlib figure.

Examples

>>> from fractions import Fraction
>>> import matplotlib.pyplot as plt
>>> from cutcutcodec.core.generation.video.matplotlib import GeneratorVideoMatplotlib
>>>
>>> def func(timestamp: Fraction) -> plt.Figure:
...     fig = plt.figure(layout="constrained", figsize=(7, 4))  # w, h
...     fig.supxlabel("abscissa")
...     fig.supylabel("ordinate")
...     axe = fig.subplots(squeeze=True)
...     axe.set_xlim([0, 1])
...     axe.set_ylim([0, 1])
...     axe.plot([0, 1], [timestamp, timestamp])  # horizontal line
...     return fig
...
>>> (stream,) = GeneratorVideoMatplotlib(func).out_streams
>>> stream.snapshot(0, (9, 9))
>>>

Initialise and create the class.

Parameters

funccallable

A user-defined function that takes in input the frame time as a rational number, and returns the filled matplotlib figure as the image of the current frame.