# Error while trying to call plot\_sensors\_connectivity

**URL:** <https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128>\
**Category:** Support & Discussions\
**Tags:** eeg, visualization, connectivity\
**Created:** [July 27, 2024, 12:05pm UTC](https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128 "2024-07-27T12:05:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![moniczek](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/moniczek/32/3795_2.png) [@moniczek](https://mne.discourse.group/u/moniczek)\
**Post date:** [July 27, 2024, 12:05pm UTC](https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128/1 "2024-07-27T12:05:14Z")

</div>

Platform Windows-11-10.0.22631-SP0  
Python 3.12.3  
├☑ mne 1.7.1 (latest release)  
├☑ mne-connectivity 0.7.0

Hello, i have trouble with plotting connectivity with plot\_sensors\_connectivity. Error is the same regardless of change od the data and parameters. After calling plot\_sensors\_connectivity dark window pops up (where the plot should be), but its unresponsive, sometimes even lags my laptop, it is hard to close it (i have to use task manager to do so). I have read posts in community about similar error, and:

1. my data i pass to plot function is not empty
2. after calling get\_montage() i have info that i have 19 electrodes
3. i tried reinstalling mne

I also found that there is open bug similar to my error [plot\_sensors\_connectivity fails when strongest conns are spatially close · Issue #148 · mne-tools/mne-connectivity · GitHub](https://github.com/mne-tools/mne-connectivity/issues/148), but its not resolved, so that is why im asking here.

My code snippet:

```python
sfreq = 500
tminanal = 0
tmaxanal = 4
baseline = (0, -0.1)
bl1epo = []

for fn2 in [bl1]:
    os.chdir(fn2)
    files2 = [fl for fl in os.listdir() if fl.endswith('.set')]
    for m in tqdm(files2):
        epochs_wid = mne.read_epochs_eeglab(m, verbose=False)
        epochs_wid = epochs_wid.pick_channels(epochs_wid.ch_names)
        epochs_wid.crop(tminanal, tmaxanal)
        bl1epo.append(epochs_wid)

bl1epoall = mne.concatenate_epochs(bl1epo)

event_counts = bl1epoall.event_id #to group all events together because they have different names
all_events_id = {key: 1 for key in event_counts.keys()}
bl1epoall.event_id = all_events_id

cona = spectral_connectivity_epochs(
    bl1epoall, method='pli', mode='multitaper', fmin=8, fmax=12, tmin=0, tmax=1,
    faverage=True, sfreq=sfreq, mt_adaptive=False, n_jobs=1
)

bl1c = cona.get_data('dense')[:, :, 0]
plot_sensors_connectivity(bl1epoall.info, bl1c, cbar_label='Alpha frequency band, time range 0-1s')

```

My error:

```python
 computing cross-spectral density for epoch 1050
    assembling connectivity matrix
[Connectivity computation done]
Backend tkagg is interactive backend. Turning interactive mode on.
Using notebook 3d backend.
Traceback (most recent call last):
  File "C:\Users\Monika\PycharmProjects\EEG_analysis\.venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-38f9b76ec237>", line 54, in <module>
    plot_sensors_connectivity(bl1epoall.info, bl1c, cbar_label='Alpha frequency band, time range 0-1s')
  File "C:\Users\Monika\PycharmProjects\EEG_analysis\.venv\Lib\site-packages\mne_connectivity\viz\_3d.py", line 95, in plot_sensors_connectivity
    vmax = np.max(con_val)
           ^^^^^^^^^^^^^^^
  File "C:\Users\Monika\PycharmProjects\EEG_analysis\.venv\Lib\site-packages\numpy\_core\fromnumeric.py", line 2899, in max
    return _wrapreduction(a, np.maximum, 'max', axis, None, out,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Monika\PycharmProjects\EEG_analysis\.venv\Lib\site-packages\numpy\_core\fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation maximum which has no identity

```

I will appreciate any help.  
Best regards,  
Monika

---

<div class="post-metadata">

**Author:** ![tsbinns](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tsbinns/32/4543_2.png) [@tsbinns](https://mne.discourse.group/u/tsbinns)\
**Post date:** [July 27, 2024, 12:28pm UTC](https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128/2 "2024-07-27T12:28:51Z")

</div>

Hi Monika,

Is there some example data you could send, e.g. via a Dropbox link? That would help to try and figure out what’s happening.

Cheers,  
Thomas

---

<div class="post-metadata">

**Author:** ![moniczek](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/moniczek/32/3795_2.png) [@moniczek](https://mne.discourse.group/u/moniczek)\
**Post date:** [July 27, 2024, 12:45pm UTC](https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128/3 "2024-07-27T12:45:41Z")

</div>

Hi Thomas,

Yes, can it be via WeTransfer? I do not have dropbox on my laptop.

There is a link, i uploaded set and fdt data.

> **[eeg\_data](https://wetransfer.com/downloads/fd6c24e5dc5dad2e6a30061a9683249b20240727124210/f1a253)**
>
> 2 files sent via WeTransfer, the simplest way to send your files around the world

Thanks for your reply,  
Monika

---

<div class="post-metadata">

**Author:** ![tsbinns](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tsbinns/32/4543_2.png) [@tsbinns](https://mne.discourse.group/u/tsbinns)\
**Post date:** [July 27, 2024, 2:05pm UTC](https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128/4 "2024-07-27T14:05:36Z")

</div>

So in the data you sent, there are no coordinates associated with the channels in the montage (all NaNs), which is causing the error (so indeed related to what you linked above, but for a slightly different reason).  
`bl1epoall.get_montage().dig`:  
 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/b/b60cf467a8a9253519e60f7ec8269951ec113cad.png)

I’ve commented and linked to your post there, so hopefully we can add a fix to catch these cases/give a clearer error in the future.

For solving your problem though, you’ll need to use a montage that has the coordinates. I’d have a look at the standard montages in case one matches your system ([`mne.channels.get_builtin_montages()`](https://mne.tools/stable/generated/mne.channels.get_builtin_montages.html#mne.channels.get_builtin_montages)).

Otherwise you’ll need to make a custom montage, either from arrays with [`mne.channels.make_dig_montage()`](https://mne.tools/stable/generated/mne.channels.make_dig_montage.html#mne.channels.make_dig_montage) or reading from a file (lots of different file types supported in the [`mne.channels`](https://mne.tools/stable/api/preprocessing.html#module-mne.channels) module).

Hope that helps!

---

<div class="post-metadata">

**Author:** ![moniczek](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/moniczek/32/3795_2.png) [@moniczek](https://mne.discourse.group/u/moniczek)\
**Post date:** [July 29, 2024, 1:50pm UTC](https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128/5 "2024-07-29T13:50:19Z")

</div>

Hi Thomas!

Thank you for your reply, it worked fine, the plot appears without errors and it looks good!  
I’ve used it like this (maybe this will help someone looking for an answer):

```python
for fn2 in [bl1]:
    os.chdir(fn2)
    files2 = [fl for fl in os.listdir() if fl.endswith('.set')]
    for m in tqdm(files2):
        epochs_wid = mne.read_epochs_eeglab(m, verbose=False)
        epochs_wid = epochs_wid.pick_channels(epochs_wid.ch_names)
        epochs_wid.crop(tminanal, tmaxanal)
        mont =mne.channels.make_standard_montage(kind='standard_1020', head_size='auto')
        epochs_wid.set_montage(mont)
        bl1epo.append(epochs_wid)

```

Once again i’m really thankful, I wish you all the best!  
Monika

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 5, 2024, 1:50pm UTC](https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128/6 "2024-08-05T13:50:39Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
