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(thensp_matrixmust be omitted). Spike times of aSpikeTrainswith time units are plotted in ms, matching the defaultxlabel.sp_matrix (np.ndarray, optional) – The spike matrix which records the spike information, with shape
(len(ts), n_neurons). Required unlesstsis aSpikeTrains. It can be easily accessed by specifying themonitorsof 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.
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
SpikeTrainsandsp_matrixare 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))