pynaviz.base_plot.PlotTsGroup#

class pynaviz.base_plot.PlotTsGroup(data, index=None, parent=None, background='black')[source]#

Bases: _BasePlot

Visualization for plotting multiple spike trains (nap.TsGroup) as a raster plot.

Each unit in the group is displayed as a row, where spike times are rendered as point markers (vertical ticks). Units can be sorted or grouped based on metadata. A SpanController is used to synchronize view ranges across plots.

Parameters:
  • data (nap.TsGroup) – A Pynapple TsGroup object containing multiple spike trains.

  • index (int, optional) – Identifier for the controller instance, useful when synchronizing multiple plots.

  • parent (QWidget, optional) – Parent widget in a Qt application, if applicable.

  • background (str | None)

__init__(data, index=None, parent=None, background='black')[source]#
Parameters:

Methods

__init__(data[, index, parent, background])

add_interval_sets(epochs[, colors, alpha, ...])

animate()

Updates the positions of rulers and reference lines based on the current world coordinate bounds and triggers a re-render of the scene.

close()

color_by(metadata_name[, cmap_name, vmin, vmax])

Applies color mapping to plot elements based on a metadata field.

from_state(state, available_vars)

Restore the full plot state from a previously saved dict.

get_plot_state()

Return spike marker sizes and visibility keyed by neuron ID.

get_state()

Return the full serializable state of this plot.

group_by(metadata_name, **kwargs)

Group the raster vertically by a metadata field.

jump_to_next_epoch()

Jump to the start of the next superposed epoch (across all added interval sets).

jump_to_previous_epoch()

Jump to the start of the previous superposed epoch (across all added interval sets).

remove_interval_set(label)

Remove an interval set from the plot.

set_plot_state(state[, available_vars])

Restore spike marker sizes and visibility.

show()

To show the canvas in case of GLFW context used

sort_by(metadata_name[, mode])

Sort the raster vertically by a metadata field.

update_interval_set(name, colors, alpha)

Update the color and transparency of an existing interval set.

Attributes

add_interval_sets(epochs, colors=None, alpha=None, labels=None)#
Parameters:
animate()#

Updates the positions of rulers and reference lines based on the current world coordinate bounds and triggers a re-render of the scene.

This method performs the following: - Computes the visible world coordinate bounds. - Updates the horizontal (x) and vertical (y) rulers accordingly. - Repositions the center time reference line in the scene. - Re-renders the scene using the current camera and canvas settings.

Notes

This method should be called whenever the visible region of the plot changes (e.g., after zooming, panning, or resizing the canvas).

close()#
property cmap#
color_by(metadata_name, cmap_name='viridis', vmin=0.0, vmax=100.0)#

Applies color mapping to plot elements based on a metadata field.

This method retrieves values from the given metadata field and maps them to colors using the specified colormap and value range. The mapped colors are applied to each plot element’s material. If color mappings are still being computed in a background thread, the function retries after a short delay.

Parameters:
  • metadata_name (str) – Name of the metadata field used for color mapping.

  • cmap_name (str, default "viridis") – Name of the colormap to apply (e.g., “jet”, “plasma”, “viridis”).

  • vmin (float, default 0.0) – Minimum value for the colormap normalization.

  • vmax (float, default 100.0) – Maximum value for the colormap normalization.

Return type:

None

Notes

  • If the color_mapping_thread is still running, the method defers execution by 25 milliseconds and retries automatically.

  • If no appropriate color map is found for the metadata, a warning is issued.

  • Requires self.data to support get_info() for metadata retrieval.

  • Triggers a canvas redraw by calling self.animate() after updating colors.

Warning

UserWarning

Raised when the specified metadata field has no associated color mapping.

property data#
from_state(state, available_vars)#

Restore the full plot state from a previously saved dict.

Guards against missing keys so that layouts saved by older versions of pynaviz can still be loaded without error.

Parameters:
  • state (dict) – Dictionary produced by get_state().

  • available_vars (dict) – Mapping of variable name nap variable used to look up overlays by name.

get_plot_state()[source]#

Return spike marker sizes and visibility keyed by neuron ID.

Returns:

{"scale": {neuron_id: size, …}, "visible": [bool, …]}.

Return type:

dict

get_state()#

Return the full serializable state of this plot.

Aggregates three layers:

  • "manager": sort_by / group_by / color_by actions.

  • "interval_sets": overlay color and alpha keyed by label.

  • "plot": plot-type-specific state (mode, scale, clim, …).

Return type:

dict

group_by(metadata_name, **kwargs)[source]#

Group the raster vertically by a metadata field.

Parameters:

metadata_name (str) – Metadata key to group by.

jump_to_next_epoch()#

Jump to the start of the next superposed epoch (across all added interval sets).

Return type:

None

jump_to_previous_epoch()#

Jump to the start of the previous superposed epoch (across all added interval sets).

Return type:

None

remove_interval_set(label)#

Remove an interval set from the plot.

Parameters:

label (str) – The label of the interval set to be removed.

Return type:

None

set_plot_state(state, available_vars=None)[source]#

Restore spike marker sizes and visibility.

Parameters:
  • state (dict) – Value produced by get_plot_state(). Integer neuron-ID keys are recovered from their JSON string representation.

  • available_vars (dict, optional) – Unused, dict of available variables.

show()#

To show the canvas in case of GLFW context used

sort_by(metadata_name, mode='ascending')[source]#

Sort the raster vertically by a metadata field.

Parameters:
  • metadata_name (str) – Metadata key to sort by.

  • mode (str, optional) – “ascending” (default) or “descending”.

Return type:

None

update_interval_set(name, colors, alpha)#

Update the color and transparency of an existing interval set.

Parameters:
  • name (str) – The label of the interval set to be updated.

  • colors (str | Color) – The new color of the interval set.

  • alpha (float) – The new transparency level, between 0 and 1.

Return type:

None