lava icon indicating copy to clipboard operation
lava copied to clipboard

Raster Plot for spiking activity

Open ackurth-nc opened this issue 3 years ago • 0 comments

Lava version:

  • [ ] 0.5.0 (feature release)
  • [ ] 0.4.1 (bug fixes)
  • [x] 0.4.0 (current version)
  • [ ] 0.3.0
  • [ ] 0.1.2

I'm submitting a ...

  • [ ] bug report
  • [x] feature request
  • [ ] documentation request

Feature request: Function to plot spiking activity of raster plot akin to one implemented in #309. Integrating this function into Lava directly suggested by @mathisrichter in discussion of #309.

def raster_plot(spks, stride=6, fig=None, color='b', alpha=1):
    """Generate raster plot of spiking activity.
    
    Parameters
    ----------
    
    spks : np.ndarray shape (num_neurons, timesteps)
        Spiking activity of neurons, a spike is indicated by a one    
    stride : int
        Stride for plotting neurons
    """
    num_time_steps = spks.shape[1]
    assert stride < num_time_steps, "Stride must be smaller than number of time steps"
    
    time_steps = np.arange(0, num_time_steps, 1)
    if fig is None:
        fig = plt.figure(figsize=(10,5))
    timesteps = spks.shape[1]
    
    plt.xlim(-1, num_time_steps)
    plt.yticks([])
    
    plt.xlabel('Time steps')
    plt.ylabel('Neurons')
    
    for i in range(0, dim, stride):
        spike_times = time_steps[spks[i] == 1]
        plt.plot(spike_times,
                 i * np.ones(spike_times.shape),
                 linestyle=' ',
                 marker='o',
                 markersize=1.5,
                 color=color,
                 alpha=alpha)
        
    return fig 

ackurth-nc avatar Sep 22 '22 13:09 ackurth-nc