# Plot a topographic map with all channel names and with a mask

**URL:** <https://mne.discourse.group/t/plot-a-topographic-map-with-all-channel-names-and-with-a-mask/5088>\
**Category:** Support & Discussions\
**Tags:** eeg, visualization\
**Created:** [June 16, 2022, 9:54am UTC](https://mne.discourse.group/t/plot-a-topographic-map-with-all-channel-names-and-with-a-mask/5088 "2022-06-16T09:54:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [June 16, 2022, 9:54am UTC](https://mne.discourse.group/t/plot-a-topographic-map-with-all-channel-names-and-with-a-mask/5088/1 "2022-06-16T09:54:54Z")

</div>

Is there a way to plot a topographic map with all channel names and with a `mask` provided to highlight specific sensors with a different plotting style?

```python
from mne.datasets import sample
from mne.io import read_raw_fif
from mne.viz import plot_topomap

directory = sample.data_path() / "MEG" / "sample"
fname = directory / "sample_audvis_raw.fif"
raw = read_raw_fif(fname, preload=False)
raw.pick_types(eeg=True, exclude=[]).crop(0, 5)
raw.load_data()
data = raw.get_data()[:, 101]

plot_topomap(data, raw.info, show_names=True, names=raw.ch_names)

```

![Screenshot 2022-06-16 at 11.46.31](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/c/c27161e9d1aa958ccf8cf882914f1ef84115dfb2.png)

But with a mask:

```python
import numpy as np

from mne.datasets import sample
from mne.io import read_raw_fif
from mne.viz import plot_topomap

directory = sample.data_path() / "MEG" / "sample"
fname = directory / "sample_audvis_raw.fif"
raw = read_raw_fif(fname, preload=False)
raw.pick_types(eeg=True, exclude=[]).crop(0, 5)
raw.load_data()
data = raw.get_data()[:, 101]

mask = np.zeros(len(raw.ch_names))
for ch in raw.info["bads"]:
    mask[raw.ch_names.index(ch)] = 1
mask.astype(bool)

plot_topomap(data, raw.info, show_names=True, names=raw.ch_names, mask=mask)

```

![Screenshot 2022-06-16 at 11.48.15](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/9/9ee1e46967b9db5cbd74863aea15f69af5929cee.png)

It looks intended as per the docstring of the `show_names` argument:

> If mask is not None, only significant sensors will be shown.

Maybe the ‘easiest’ way would be to plot first without a `mask` and then overlay a mask on the matplotlib axes… anyone has a better idea before I go this way?

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [June 16, 2022, 3:52pm UTC](https://mne.discourse.group/t/plot-a-topographic-map-with-all-channel-names-and-with-a-mask/5088/2 "2022-06-16T15:52:33Z")

</div>

just to be sure I understand: what you want isn’t shown in either of those images, right? You want to show _all_ sensor names, but have a few of them (determined by `mask`) in bold font, or larger font, or another color, or something like that? Would it be too hard to iterate through `list(axes.texts)` and e.g. `.set_color('red')` on each one whose `.get_text()` matches the channels you want to mask?

In other words, is a one-off figure for a paper, or is this a general enough use case that we should support it? What if the style of highlighting is not to all users’ tastes, do we need to expose color, opacity, family, weight, and size params?

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [June 16, 2022, 4:33pm UTC](https://mne.discourse.group/t/plot-a-topographic-map-with-all-channel-names-and-with-a-mask/5088/3 "2022-06-16T16:33:06Z")

</div>

You got it perfectly right. I’ll give a try to your suggestion. I am not super familiar with the matplotlib API, and finding the sensors’ symbols to change the settings and redraw the figure is not super straightforward.

One-time or missing feature, that’s an open discussion. For the `mask`, my goal was to find bridged EEG electrodes and plot them with [mne.viz.plot\_bridged\_electrodes — MNE 1.1.dev0 documentation](https://mne.tools/dev/generated/mne.viz.plot_bridged_electrodes.html)  
For each group of N bridged electrodes, I wanted to retain 1 electrode and mark as bad for interpolation N-1 electrodes; and for visualization, I wanted to add a mask with the electrodes set as bad. It would help to visualize the different rules/logic I could add.

It’s a special case, and I don’t think the `mask` is that used anyway… but I think the `mne.viz.plot_topomap` could use a bit of love, e.g. the arguments `names` and `show_names` are not straightforward to use (and overall the mix between `pos` as an `array` and as an `Info` is making a mess out of the arguments).

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [June 17, 2022, 1:18pm UTC](https://mne.discourse.group/t/plot-a-topographic-map-with-all-channel-names-and-with-a-mask/5088/4 "2022-06-17T13:18:52Z")

</div>

> [@mscheltienne](#):
>
> For each group of N bridged electrodes, I wanted to retain 1 electrode and mark as bad for interpolation N-1 electrodes; and for visualization, I wanted to add a mask with the electrodes set as bad. It would help to visualize the different rules/logic I could add.

I find this convincing as a use case, and am generally in favor of visualization methods designed to help users diagnose or detect problems with their data (such as bridged electrodes).

> [@mscheltienne](#):
>
> I think the `mne.viz.plot_topomap` could use a bit of love

Go for it. I’m still a bit unsure about exposing the channel label styling in the public API though… but it’s not clear to me if that’s what you want to do, or if instead you want to improve `plot_bridged_electrodes` to visualize things differently than the current “red connecting lines” approach.
