mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.72k stars 1.32k forks source link

IndexError when clicking on trace in ICA.plot_overlay() #9342

Open hoechenberger opened 3 years ago

hoechenberger commented 3 years ago

MWE:

from pathlib import Path
import matplotlib
import mne

matplotlib.use('Qt5Agg')

sample_dir = Path(mne.datasets.sample.data_path())
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

raw = mne.io.read_raw_fif(sample_fname).pick_types(meg=False, eeg=True,
                                                   stim=True)

events = mne.find_events(raw, stim_channel='STI 014')
event_id = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
            'visual/right': 4, 'face': 5, 'buttonpress': 32}

epochs = mne.Epochs(raw, events=events, event_id=event_id,
                    tmin=-0.2, tmax=0.5, baseline=None,
                    preload=True)

ica = mne.preprocessing.ICA(n_components=0.8, method='picard', max_iter=500)
ica.fit(epochs)

ica.plot_overlay(inst=epochs.average().apply_baseline())

https://user-images.githubusercontent.com/2046265/115895458-ba078900-a45a-11eb-95ac-9e97e86c3de3.mov

Traceback:

Traceback (most recent call last):
  File "/Users/hoechenberger/miniforge3/envs/mne/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 270, in process
    func(*args, **kwargs)
  File "/Users/hoechenberger/Development/mne-python/mne/viz/evoked.py", line 52, in _butterfly_onpick
    lidx = np.where([
IndexError: index 0 is out of bounds for axis 0 with size 0
Traceback (most recent call last):
  File "/Users/hoechenberger/miniforge3/envs/mne/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 270, in process
    func(*args, **kwargs)
  File "/Users/hoechenberger/Development/mne-python/mne/viz/evoked.py", line 52, in _butterfly_onpick
    lidx = np.where([
IndexError: index 0 is out of bounds for axis 0 with size 0
drammock commented 3 years ago

sticking a print statement into _butterfly_onpick shows that the pick handler is getting called 4 times per click (twice for the black line, and twice for the red line superimposed on it). I see this behavior even on Matplotlib latest dev version (https://github.com/matplotlib/matplotlib/commit/93e716de372a8d6e95f999ce60ea8965d1488c4c). I was hoping it was already solved by https://github.com/matplotlib/matplotlib/pull/19611 but apparently this is a different problem.