dq.plot.gifit
gifit(
plot_function: callable[[T, ...], None],
gif_duration: float = 5.0,
fps: int = 10,
filename: str = ".tmp/dynamiqs/gifit.gif",
dpi: int = 72,
display: bool = True,
) -> callable[[Sequence[T], ...], None]
Transform a plot function into a function that creates an animated GIF.
This function takes a plot function that normally operates on a single input and returns a function that creates a GIF from a sequence of inputs.
Warning
This function creates files in the current working directory under
.tmp/dynamiqs
to store the GIF frames. The directory is automatically deleted
when the function ends. Specify the argument filename
to save the GIF
on your disk.
Note
By default, the GIF is displayed in Jupyter notebook environments.
Parameters
-
plot_function
–
Plot function which must take as first positional argument the input that will be sequenced over by the new function. It must create a matplotlib
Figure
object and not close it. -
gif_duration
–
GIF duration in seconds.
-
fps
–
GIF frames per seconds.
-
filename
–
Save path of the GIF file.
-
dpi
–
GIF resolution.
-
display
–
If
True
, the GIF is displayed in Jupyter notebook environments.
Returns
A new function with the same signature as plot_function
which accepts a
sequence of inputs and creates a GIF by applying the original
plot_function
to each element in the sequence.
Examples
>>> def plot_cos(phi):
... x = np.linspace(0, 1.0, 501)
... y = np.cos(2 * np.pi * x + phi)
... plt.plot(x, y)
>>> phis = np.linspace(0, 2 * np.pi, 101)
>>> filename = 'docs/figs_code/cos.gif'
>>> plot_cos_gif = dq.plot.gifit(
... plot_cos, fps=25, filename=filename, dpi=150, display=False
... )
>>> plot_cos_gif(phis)
>>> alphas = jnp.linspace(0.0, 3.0, 51)
>>> states = dq.coherent(24, alphas)
>>> filename = 'docs/figs_code/coherent_evolution.gif'
>>> plot_fock_gif = dq.plot.gifit(
... dq.plot.fock, fps=25, filename=filename, dpi=150, display=False
... )
>>> plot_fock_gif(states)