raster_plot

Contents

raster_plot#

class braintools.visualize.raster_plot(ts, sp_matrix=None, ax=None, marker='.', markersize=2, color='k', xlabel='Time (ms)', ylabel='Neuron index', xlim=None, ylim=None, title=None, show=False, alpha=1.0, **kwargs)#

Show the raster plot of the spikes.

Parameters:
  • ts (np.ndarray or SpikeTrains) – The run times, or a braintools.spike.SpikeTrains (then sp_matrix must be omitted). Spike times of a SpikeTrains with time units are plotted in ms, matching the default xlabel.

  • sp_matrix (np.ndarray, optional) – The spike matrix which records the spike information, with shape (len(ts), n_neurons). Required unless ts is a SpikeTrains. It can be easily accessed by specifying the monitors of NeuGroup by: neu = NeuGroup(..., monitors=['spike'])

  • ax (Axes, optional) – The figure axes. If None, uses plt.

  • marker (str) – The marker style.

  • markersize (int) – The size of the marker.

  • color (str) – The color of the marker.

  • xlim (list, tuple, optional) – The xlim.

  • ylim (list, tuple, optional) – The ylim.

  • xlabel (str) – The xlabel.

  • ylabel (str) – The ylabel.

  • title (str, optional) – The plot title.

  • show (bool) – Show the figure.

  • alpha (float) – Alpha transparency value.

  • **kwargs – Additional keyword arguments passed to scatter().

Returns:

ax – The axes object containing the plot.

Return type:

matplotlib.axes.Axes

Raises:

ValueError – If ts is None or sp_matrix is empty, or if both a SpikeTrains and sp_matrix are given.

Examples

>>> import jax.numpy as jnp
>>> import brainunit as u
>>> from braintools.spike import SpikeTrains
>>> from braintools.visualize import raster_plot
>>> spikes = jnp.zeros((100, 5)).at[::10, 2].set(1.)
>>> ax = raster_plot(jnp.arange(100) * 0.1, spikes)            # legacy form
>>> ax = raster_plot(SpikeTrains.from_dense(spikes, dt=0.1 * u.ms))