Widgets module

The spikeinterface.widgets module includes plotting function to visualize recordings, sortings, waveforms, and more.

Since version 0.95.0, the spikeinterface.widgets module supports multiple backends:

  • matplotlib: static rendering using the matplotlib package
  • ipywidgets: interactive rendering within a jupyter notebook using the
    ipywidgets package
  • sortingview: web-based and interactive rendering using the sortingview
    and FIGURL packages.

Version 0.99.0 also comes with this new backend:

  • ephyviewer: interactive Qt based using the ephyviewer package

Installing backends

The backends are loaded at run-time and can be installed separately. Alternatively, all dependencies from all backends can be installed with:

pip install spikeinterface[widgets]

matplotlib

The matplotlib backend (default) uses the matplotlib package to generate static figures.

To install it, run:

pip install matplotlib

ipywidgets

The ipywidgets backend allows users to interact with the plot, for example, by selecting units or scrolling through a time series.

To install it, run:

pip install matplotlib ipympl ipywidgets

To enable interactive widgets in your notebook, add and run a cell with:

%matplotlib widget

sortingview

The sortingview backend generates web-based and shareable links that can be viewed in the browser.

To install it, run:

pip install sortingview

Internally, the processed data to be rendered are uploaded to a public bucket in the cloud, so that they can be visualized via the web (if generate_url=True). When running in a Jupyter notebook or JupyterLab, the sortingview widget will also be rendered in the notebook!

To set up the backend, you need to authenticate to kachery-cloud using your GitHub account by running the following command (you will be prompted with a link):

kachery-cloud-init

Finally, if you wish to set up another cloud provider, follow the instruction from the kachery-cloud package (“Using your own storage bucket”).

ephyviewer

This backend is Qt based with PyQt5, PyQt6 or PySide6 support. Qt is sometimes tedious to install.

For a pip-based installation, run:

pip install PySide6 ephyviewer

Anaconda users will have a better experience with this:

conda install pyqt=5
pip install ephyviewer

Usage

You can specify which backend to use with the backend argument. In addition, each backend comes with specific arguments that can be set when calling the plotting function.

A default backend for a SpikeInterface session can be set with the set_default_plotter_backend() function:

# matplotlib backend
set_default_plotter_backend(backend="ipywidgets")
print(get_default_plotter_backend())
# >>> "ipywidgets"

All plot_* functions return a BackendPlotter instance. Different backend-specific plotters can expose different attributes. For example, the matplotlib plotter has the figure, ax, and axes (for multi-axes plots) attributes to enable further customization.

matplotlib

The plot_*(..., backend="matplotlib") functions come with the following additional (and optional) arguments:

  • figure: Matplotlib figure. When None, it is created. Default None

  • ax: Single matplotlib axis. When None, it is created. Default None

  • axes: Multiple matplotlib axes. When None, they are created. Default None

  • ncols: Number of columns to create in subplots. Default 5

  • figsize: Size of matplotlib figure. Default None

  • figtitle: The figure title. Default None

# matplotlib backend
w = plot_traces(recording=recording, backend="matplotlib")

Output:

../_images/mpl_timeseries.png

ipywidgets

The plot_*(..., backend="ipywidgets") functions are only available in Jupyter notebooks or JupyterLab after calling the %matplotlib widget magic line. Each function has the following additional arguments:

  • width_cm: Width of the figure in cm (default 10)

  • height_cm: Height of the figure in cm (default 6)

  • display: If True, widgets are immediately displayed

from spikeinterface.preprocessing import common_reference

# ipywidgets backend also supports multiple "layers" for plot_traces
rec_dict = dict(filt=recording, cmr=common_reference(recording))
w = sw.plot_traces(recording=rec_dict, backend="ipywidgets")

Output:

../_images/ipy_timeseries.gif

sortingview

The plot_*(..., backend="sortingview") generate web-based GUIs, which are also shareable with a link (provided that kachery-cloud is correctly setup, see sortingview). The functions have the following additional arguments:

  • generate_url: If True, the figurl URL is generated and printed. Default True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell. Default True

  • figlabel: The figurl figure label. Default None

  • height: The height of the sortingview View in jupyter. Default None

# sortingview backend
w_ts = sw.plot_traces(recording=recording, backend="sortingview")
w_ss = sw.plot_sorting_summary(waveform_extractor=we, curation=True, backend="sortingview")

Output:

../_images/sv_timeseries.png ../_images/sv_summary.png

The sortingview plotter allows one to combine multiple View`s using the :code:`sortingview API. For example, here is how to combine the timeseries and sorting summary generated above in multiple tabs:

import sortingview.views as vv

v_ts = w_ts.view
v_ss = w_ss.ciew

v_summary = vv.TabLayout(
                items=[
                    vv.TabLayoutItem(
                        label='Timeseries',
                        view=v_ts
                    ),
                    vv.TabLayoutItem(
                        label='Sorting Summary',
                        view=v_ss
                    )
                ]
            )
# generate URL
url = v_summary.url(label="Example multiple tabs")
print(url)

ephyviewer

The ephyviewer backend is currently only available for the plot_traces() function.

plot_traces(recording=recording, backend="ephyviewer", mode="line", show_channel_ids=True)
../_images/plot_traces_ephyviewer.png

Available plotting functions