pyFDN.animate#

pyFDN.animate(plot_fn, frames, *, labels=None, label_prefix='', label_format='', frame_ms=300, title=None)[source]#

Animate a sequence of frames built by any per-frame plotting function.

plot_fn(frame) is called for each entry in frames and must return a Matplotlib figure (e.g. plot_matrix(), plot_impulse_response()). Each figure is rendered to one image, and the images are played back as a matplotlib.animation.FuncAnimation. Build every frame with the same size and fixed axis/color limits so the frames line up.

This composes with the existing plot_* builders instead of re-deriving their styling. To animate a matrix C of shape (rows, cols, T) over time, with fixed color limits, and show it with player controls in a notebook:

import functools

anim = pyFDN.animate(
    functools.partial(pyFDN.plot_matrix, zmin=-1, zmax=1),
    [C[:, :, k] for k in range(C.shape[2])],
    labels=t,
    label_prefix="t = ",
    label_format=".2f",
)
mo.Html(anim.to_jshtml())  # or IPython.display.HTML(...)
Parameters:
  • plot_fn (Callable[[Any], Any]) – Maps one frames entry to a Matplotlib figure. Use functools.partial() or a lambda to fix extra arguments (e.g. color limits) so every frame is built consistently.

  • frames (Sequence[Any]) – One argument per frame, passed positionally to plot_fn.

  • labels (Sequence[Any] | None) – Label shown above each frame. Defaults to the frame index.

  • label_prefix (str) – Prefix shown before the current label (e.g. "t = ").

  • label_format (str) – Format spec applied to each label, e.g. ".2f". Empty uses str.

  • frame_ms (int) – Per-frame duration in milliseconds during playback. Default 300.

  • title (str | None) – Title shown above the frame label.

Returns:

Use .to_jshtml() for an interactive player or .save() to write a GIF or video.

Return type:

Any