# plot\_sensors\_connectiviy result doesn't agree with connectivity matrix

**URL:** <https://mne.discourse.group/t/plot-sensors-connectiviy-result-doesnt-agree-with-connectivity-matrix/11035>\
**Category:** Support & Discussions\
**Tags:** eeg, visualization\
**Created:** [March 28, 2025, 11:45am UTC](https://mne.discourse.group/t/plot-sensors-connectiviy-result-doesnt-agree-with-connectivity-matrix/11035 "2025-03-28T11:45:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaqing](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/yaqing/32/2503_2.png) [@yaqing](https://mne.discourse.group/u/yaqing)\
**Post date:** [March 28, 2025, 11:45am UTC](https://mne.discourse.group/t/plot-sensors-connectiviy-result-doesnt-agree-with-connectivity-matrix/11035/1 "2025-03-28T11:45:16Z")

</div>

Dear Forum,

I ran into some problem with plotting all-to-all EEG sensor connectivity using the funcion plot\_sensors\_connectivity(). The connectivity is computed from epoch data and transformed into matrix form:

```python
conn = mne_connectivity.spectral_connectivity_epochs(epochs_fl.get_data(), method='coh', fmin=bands[band][0], fmax=bands[band][1], sfreq=sfreq)
conn_matrix = conn.get_data(output="dense")[:, :, 0]

```

When I visualize my connectivity matrix it looks fine

 ![EEG_sensor_conn_example](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/1/1a84a2f1fc7182b32d8ed2bf70d80432ee79c696.png)

However, when I try `plot_sensors_connectivity(epochs_fl.info, conn_matrix)` there are only 2 connections with very high connectivity strength:

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/b/bf62ffba8b5524f89ed6d49f639ab96a364510c9.png)

I have checked my EEG montage using `epochs_fl.get_montage().dig`and it seems to have the sensor location info. What could be wrong here?

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/4/400bf810ed3bf976f1f9c8d0a59cf20b96bc0bd6.png)

---

<div class="post-metadata">

**Author:** ![yaqing](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/yaqing/32/2503_2.png) [@yaqing](https://mne.discourse.group/u/yaqing)\
**Post date:** [March 28, 2025, 12:33pm UTC](https://mne.discourse.group/t/plot-sensors-connectiviy-result-doesnt-agree-with-connectivity-matrix/11035/2 "2025-03-28T12:33:03Z")

</div>

The problem seems to be due to the hard-coded minimal distance, and fixed by:

> <https://github.com/mne-tools/mne-connectivity/pull/221>
>
> Addresses #148, discussed in call with @larsoner.
> 
> Have gone with options (2) …& (3) suggested above. This involves:
> \- An option to specify the minimum distance required between sensors for a connection to be plotted (default was 5 cm, which has been retained).
> \- A check that if no connections survive the minimum distance requirement, a more descriptive error message is raised.
> - The message suggests increasing the number of connections being plotted or decreasing the minimum distance (would help in cases like https://mne.discourse.group/t/problem-with-different-methods-in-sensor-connectivity-example/7548/4)
> - The message also suggests checking that the coordinates of channels are not NaNs (would help in cases like https://mne.discourse.group/t/error-while-trying-to-call-plot-sensors-connectivity/9128)

Perhaps this can be merged?

---

<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:** [April 6, 2025, 3:15pm UTC](https://mne.discourse.group/t/plot-sensors-connectiviy-result-doesnt-agree-with-connectivity-matrix/11035/3 "2025-04-06T15:15:49Z")

</div>

Hello,

Sorry for the late reply, I was away on vacation.

This fix has been merged into the development version of the package which you can install with `pip install git+https://github.com/mne-tools/mne-connectivity`. If you want the fix, working with the development version is your best bet. As far as I’m aware there’s no set date for when it will be officially released, and it’s stable enough in its current state.

You can find the documentation for the new `min_distance` parameter here: [mne\_connectivity.viz.plot\_sensors\_connectivity — MNE-Connectivity 0.8.0.dev66+gc7090ac2 documentation](https://mne.tools/mne-connectivity/dev/generated/mne_connectivity.viz.plot_sensors_connectivity.html)

Cheers,  
Thomas
