pyFDN.animate#

pyFDN.animate(plot_fn, frames, *, labels=None, label_prefix='', label_format='', frame_ms=300, transition_ms=0, 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 single-subplot Plotly figure (e.g. plot_matrix(), plot_impulse_response()). The traces of each figure become one animation frame; the first figure supplies the base layout (size, axes, color scale), to which a play/pause button and a slider are added.

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:

import functools

fig = 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",
)
fig.show()
Parameters:
  • plot_fn (callable) – Maps one frames entry to a Plotly figure. Use functools.partial() or a lambda to fix extra arguments (e.g. color limits) so every frame is built consistently.

  • frames (sequence) – One argument per frame, passed positionally to plot_fn.

  • labels (sequence, optional) – Slider label per frame. Defaults to the frame index.

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

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

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

  • transition_ms (int, optional) – Tween duration between frames in milliseconds. Default 0.

  • title (str, optional) – Figure title. If None, the first frame’s title is kept.

Returns:

Call .show() to display.

Return type:

go.Figure