Creating channel groups manually

Hello,

  • MNE-Python version: 0.22.0
  • operating system: windows 10

I have a set of hand picked channels for which I would like to plot their sensor positions with different colors.
I want to use the mne.viz.plot_sensors with its ch_groups, set to my hand picked groups as follows:

hist_bins = [["AF3","AF7","Fp1"],
             ["Fpz","AFz"],
             ["AF4","AF8","Fp2"],
             ["F9","FT9","FT7","F7"],
             ["F5","F1","FC5","FC3","FC1","F3"],
             ["Fz","FCz"],
             ["F2","F6","FC2","FC4","FC6","F4"],
             ["FT8","F10","FT10","F8"],
             ["TP7","TP9","T7"],
             ["C5","C1","C3"],
             ["C2","C6","C4"],
             ["TP8","TP10","T8"],
             ["P3","CP3","P5","P7","P9","CP5"],
             ["CP1","P1"],
             ["CPz","Pz"],
             ["CP2","P2"],
             ["CP4","CP6","P6","P8","P10","P4"],
             ["PO7","O1","PO3"],
             ["POz","Oz"],
             ["O2","PO8","PO4"],
             ]
montage = mne.channels.make_standard_montage("standard_1020")
info = mne.create_info(montage.ch_names,256,"eeg")
raw = mne.io.RawArray(np.zeros((len(montage.ch_names),1)),info)
raw.set_montage(montage)

a = []
for group in hist_bins:    
    a.append(mne.pick_channels(group,include=montage.ch_names))

groups = np.array(a)
mne.viz.plot_sensors(raw.info,ch_groups=groups)

The problem is unlike the docs say the groups variable contains the following elements:
image

How may I get this task done?

The function is behaving correctly. The docstring says:

Returns the indices of ``ch_names`` in ``include`` but not in ``exclude``.

Therefore you get indices 0 ... N for N channel names.

I believe you’ll want to do something like this instead:

groups = []
for ch_names in hist_bins:
    indices = [raw.ch_names.index(ch_name) for ch_name in ch_names]
    groups.append(indices)

mne.viz.plot_sensors(raw.info, ch_groups=groups, show_names=True)

Thanks, That was exactly what I wanted to get as a result.