animator#
- class braintools.visualize.animator(data, fig, ax, num_steps=False, interval=40, cmap='plasma')#
Generate an animation by looping through the first dimension of a sample of image-like data. Time must be the first dimension of
data.Example:
import numpy as np import matplotlib.pyplot as plt from IPython.display import HTML from braintools.visualize import animator # A single sample across 100 time steps of 28x28 frames spike_data_sample = np.random.rand(100, 28, 28) fig, ax = plt.subplots() anim = animator(spike_data_sample, fig, ax) HTML(anim.to_html5_video()) # Save as a gif anim.save("spike_mnist.gif", writer="pillow")
- Parameters:
data (array-like) – Data array of shape
(num_steps, height, width). Accepts NumPy, JAX, orbrainunitarrays (converted internally).fig (matplotlib.figure.Figure) – Top level container for all plot elements.
ax (matplotlib.axes.Axes) – Axes that set the coordinate system, e.g.
fig, ax = plt.subplots(facecolor='w', figsize=(12, 7)).num_steps (int, optional) – Number of time steps to plot. When falsy (the default
Falseor0), every entry along the first dimension ofdatais used.interval (int, optional) – Delay between frames in milliseconds, defaults to
40.cmap (str, optional) – Color map, defaults to
"plasma".
- Returns:
anim – Animation to be displayed (e.g. via
anim.to_html5_video()) or saved withanim.save(...).- Return type:
matplotlib.animation.ArtistAnimation