diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index 1a54e4f00b0..ad5f0e21e33 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -173,6 +173,8 @@ Enhancements Bugs ~~~~ +- Fix bug with :func:`mne.viz.plot_evoked_topo` where set ylim parameters gets swapped across channel types. (:gh:`9207` by |Ram Pari|_) + - Fix bug with :func:`mne.io.read_raw_edf` where µV was not correctly recognized (:gh:`9187` **by new contributor** |Sumalyo Datta|_) - Fix bug with :func:`mne.viz.plot_compare_evokeds` did not check type of combine. (:gh:`9151` **by new contributor** |Matteo Anelli|_) diff --git a/mne/viz/topo.py b/mne/viz/topo.py index f4931e16d91..5ee93709abd 100644 --- a/mne/viz/topo.py +++ b/mne/viz/topo.py @@ -230,16 +230,9 @@ def _plot_topo(info, times, show_func, click_func=None, layout=None, fig_facecolor=fig_facecolor, unified=unified, img=img, axes=axes) - # Temporarily converting the ylim to a list to avoid zip object exhaustion - if ylim is not None: - ylim_list = [list(t) for t in zip(*ylim)] - else: - ylim_list = ylim - for ax, ch_idx in my_topo_plot: - if layout.kind == 'Vectorview-all' and ylim_list is not None: + if layout.kind == 'Vectorview-all' and ylim is not None: this_type = {'mag': 0, 'grad': 1}[channel_type(info, ch_idx)] - ylim = zip(*ylim_list) ylim_ = [v[this_type] if _check_vlim(v) else v for v in ylim] else: ylim_ = ylim @@ -713,16 +706,19 @@ def _plot_evoked_topo(evoked, layout=None, layout_scale=0.945, color=None, if not merge_channels: # XXX. at the moment we are committed to 1- / 2-sensor-types layouts - chs_in_layout = set(layout.names) & set(ch_names) - types_used = {channel_type(info, ch_names.index(ch)) - for ch in chs_in_layout} + chs_in_layout = [ch_name for ch_name in ch_names + if ch_name in layout.names] + types_used = [channel_type(info, ch_names.index(ch)) + for ch in chs_in_layout] + # Using dict conversion to remove duplicates + types_used = list(dict.fromkeys(types_used)) # remove possible reference meg channels - types_used = set.difference(types_used, set('ref_meg')) + types_used = [types_used for types_used in types_used + if types_used != 'ref_meg'] # one check for all vendors - meg_types = {'mag', 'grad'} - is_meg = len(set.intersection(types_used, meg_types)) > 0 - nirs_types = {'hbo', 'hbr', 'fnirs_cw_amplitude', 'fnirs_od'} - is_nirs = len(set.intersection(types_used, nirs_types)) > 0 + is_meg = len([x for x in types_used if x in ['mag', 'grad']]) > 0 + is_nirs = len([x for x in types_used if x in + ('hbo', 'hbr', 'fnirs_cw_amplitude', 'fnirs_od')]) > 0 if is_meg: types_used = list(types_used)[::-1] # -> restore kwarg order picks = [pick_types(info, meg=kk, ref_meg=False, exclude=[]) @@ -768,7 +764,10 @@ def _plot_evoked_topo(evoked, layout=None, layout_scale=0.945, color=None, if len(ylim_) == 1: ylim_ = ylim_[0] else: - ylim_ = zip(*[np.array(yl) for yl in ylim_]) + ylim_ = [np.array(yl) for yl in ylim_] + # Transposing to avoid Zipping confusion + if is_meg or is_nirs: + ylim_ = list(map(list, zip(*ylim_))) else: raise TypeError('ylim must be None or a dict. Got %s.' % type(ylim))