src.canns.analyzer.plotting.spikes

Spike train visualization helpers.

Functions

average_firing_rate_plot(spike_train, dt[, config, ...])

Calculate and plot average neural activity from a spike train.

population_activity_heatmap(activity_data, dt[, ...])

Generate a heatmap of population firing rate activity over time.

raster_plot(spike_train[, config, mode, title, ...])

Generate a raster plot from a spike train matrix.

Module Contents

src.canns.analyzer.plotting.spikes.average_firing_rate_plot(spike_train, dt, config=None, *, mode='population', weights=None, title='Average Firing Rate', figsize=(12, 5), save_path=None, show=True, **kwargs)[source]

Calculate and plot average neural activity from a spike train.

Parameters:
  • spike_train (numpy.ndarray) – Boolean/integer array of shape (timesteps, neurons).

  • dt (float) – Simulation time step in seconds.

  • config (src.canns.analyzer.plotting.config.PlotConfig | None) – Optional PlotConfig with styling overrides.

  • mode (str) – One of "per_neuron", "population" or "weighted_average".

  • weights (numpy.ndarray | None) – Neuron-wise weights required for "weighted_average".

  • title (str) – Plot title when config is not provided.

  • figsize (tuple[int, int]) – Figure size forwarded to Matplotlib when creating the axes.

  • save_path (str | None) – Optional path used to persist the plot.

  • show (bool) – Whether to display the plot interactively.

  • **kwargs (Any) – Additional keyword arguments forwarded to Matplotlib.

src.canns.analyzer.plotting.spikes.population_activity_heatmap(activity_data, dt, config=None, *, title='Population Activity', xlabel='Time (s)', ylabel='Neuron Index', figsize=(10, 6), cmap='viridis', save_path=None, show=True, **kwargs)[source]

Generate a heatmap of population firing rate activity over time.

This function creates a 2D visualization where each row represents a neuron and each column represents a time point, with color indicating the firing rate or activity level.

Parameters:
  • activity_data (numpy.ndarray) – 2D array of shape (timesteps, neurons) containing firing rates or activity values.

  • dt (float) – Simulation time step in seconds.

  • config (src.canns.analyzer.plotting.config.PlotConfig | None) – Optional PlotConfig with styling overrides.

  • title (str) – Plot title when config is not provided.

  • xlabel (str) – X-axis label when config is not provided.

  • ylabel (str) – Y-axis label when config is not provided.

  • figsize (tuple[int, int]) – Figure size forwarded to Matplotlib when creating the axes.

  • cmap (str) – Colormap name (default: “viridis”).

  • save_path (str | None) – Optional path used to persist the plot.

  • show (bool) – Whether to display the plot interactively.

  • **kwargs (Any) – Additional keyword arguments forwarded to Matplotlib.

Returns:

(figure, axis) objects.

Return type:

tuple

Example

>>> import numpy as np
>>> from canns.analyzer.plotting.spikes import population_activity_heatmap
>>> # Simulate some activity data
>>> activity = np.random.rand(1000, 100)  # 1000 timesteps, 100 neurons
>>> fig, ax = population_activity_heatmap(activity, dt=0.001)
src.canns.analyzer.plotting.spikes.raster_plot(spike_train, config=None, *, mode='block', title='Raster Plot', xlabel='Time Step', ylabel='Neuron Index', figsize=(12, 6), color='black', save_path=None, show=True, **kwargs)[source]

Generate a raster plot from a spike train matrix.

The explanatory text mirrors the former visualize module so callers see the same guidance after the reorganisation.

Parameters:
  • spike_train (numpy.ndarray) – Boolean/integer array of shape (timesteps, neurons).

  • config (src.canns.analyzer.plotting.config.PlotConfig | None) – Optional PlotConfig with shared styling options.

  • mode (str) – Either "scatter" or "block" to pick the rendering style.

  • title (str) – Plot title when config is not provided.

  • xlabel (str) – X-axis label when config is not provided.

  • ylabel (str) – Y-axis label when config is not provided.

  • figsize (tuple[int, int]) – Figure size forwarded to Matplotlib when creating the axes.

  • color (str) – Spike colour (or “on” colour for block mode).

  • save_path (str | None) – Optional path used to persist the plot.

  • show (bool) – Whether to display the plot interactively.

  • **kwargs (Any) – Additional keyword arguments passed through to Matplotlib.