From 05e372e13dbfcb1f62f5e1969d1d3e12a57d4a49 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 2 May 2022 10:34:36 -0700 Subject: [PATCH 1/2] more intuitive colormaps --- examples/preprocessing/eeg_bridging.py | 19 ++++++++++++++++--- mne/viz/topomap.py | 5 ++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/preprocessing/eeg_bridging.py b/examples/preprocessing/eeg_bridging.py index 1c7f4ee36fa..61fcf50d480 100644 --- a/examples/preprocessing/eeg_bridging.py +++ b/examples/preprocessing/eeg_bridging.py @@ -35,6 +35,7 @@ import numpy as np import matplotlib.pyplot as plt +from matplotlib.colors import LinearSegmentedColormap import mne @@ -236,13 +237,25 @@ # 04-modality-specific-files/03-electroencephalography.html\ # #electrodes-description-_electrodestsv>`_ file. # Since the impedances are not stored for this dataset, we will fake -# them to demonstrate how they would be plotted. +# them to demonstrate how they would be plotted. Here, the impedances +# are plotted as is typical at the end of a setup; most channels are +# good but there are a few that need to have their impedance lowered. +# The impedances should ideally all be less than 25 KOhm before +# starting an experiment when using active systems and less than 5 KOhm +# when using a passive system. rng = np.random.default_rng(11) # seed for reproducibility raw = raw_data[1] -impedances = rng.random((len(raw.ch_names,))) * 10 +# typically impedances < 25 kOhm are acceptable for active systems and +# impedances < 5 kOhm are desirable for a passive system +impedances = rng.random((len(raw.ch_names,))) * 30 +impedances[10] = 80 # set a few bad impendances +impedances[25] = 99 +cmap = LinearSegmentedColormap.from_list(name='impedance_cmap', + colors=['g', 'y', 'r'], N=256) fig, ax = plt.subplots(figsize=(5, 5)) -im, cn = mne.viz.plot_topomap(impedances, raw.info, axes=ax) +im, cn = mne.viz.plot_topomap(impedances, raw.info, axes=ax, + cmap=cmap, vmin=25, vmax=75) ax.set_title('Electrode Impendances') cax = fig.colorbar(im, ax=ax) cax.set_label(r'Impedance (k$\Omega$)') diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 464885ed3e8..87caa7d1c46 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -964,7 +964,9 @@ def _plot_topomap(data, pos, vmin=None, vmax=None, cmap=None, sensors=True, norm = min(data) >= 0 vmin, vmax = _setup_vmin_vmax(data, vmin, vmax, norm) if cmap is None: - cmap = plt.get_cmap('Reds' if norm else 'RdBu_r') + cmap = 'Reds' if norm else 'RdBu_r' + elif isinstance(cmap, str): + cmap = plt.get_cmap(cmap) outlines = _make_head_outlines(sphere, pos, outlines, (0., 0.)) assert isinstance(outlines, dict) @@ -2687,6 +2689,7 @@ def plot_bridged_electrodes(info, bridged_idx, ed_matrix, title=None, else: topomap_args = topomap_args.copy() # don't change original topomap_args.setdefault('image_interp', 'voronoi') + topomap_args.setdefault('cmap', 'summer_r') topomap_args.setdefault('names', info.ch_names) topomap_args.setdefault('show_names', True) topomap_args.setdefault('contours', False) From 9335f01ee3117eed60ea0b3b7787e29cd03eb5ee Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 2 May 2022 10:37:38 -0700 Subject: [PATCH 2/2] revert --- mne/viz/topomap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 87caa7d1c46..966d168c864 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -964,7 +964,7 @@ def _plot_topomap(data, pos, vmin=None, vmax=None, cmap=None, sensors=True, norm = min(data) >= 0 vmin, vmax = _setup_vmin_vmax(data, vmin, vmax, norm) if cmap is None: - cmap = 'Reds' if norm else 'RdBu_r' + cmap = plt.get_cmap('Reds' if norm else 'RdBu_r') elif isinstance(cmap, str): cmap = plt.get_cmap(cmap)