Skip to content

Commit

Permalink
Add cmap argument for mne.viz.utils.plot_sensors (#11720)
Browse files Browse the repository at this point in the history
  • Loading branch information
Genuster authored Jun 6, 2023
1 parent c19bce3 commit a8ec5d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Current (1.5.dev0)

Enhancements
~~~~~~~~~~~~
- Add ``cmap`` argument for the :func:`mne.viz.plot_sensors` (:gh:`11720` by :newcontrib:`Gennadiy Belonosov`)
- When failing to locate a file, we now print the full path in quotation marks to help spot accidentally added trailing spaces (:gh:`11718` by `Richard Höchenberger`_)

Bugs
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
.. _Fu-Te Wong: https://github.com/zuxfoucault
.. _Gennadiy Belonosov: https://github.com/Genuster
.. _Geoff Brookshire: https://github.com/gbrookshire
.. _George O'Neill: https://georgeoneill.github.io
Expand Down
11 changes: 8 additions & 3 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,8 @@ def plot_sensors(
sphere=None,
pointsize=None,
linewidth=2,
*,
cmap=None,
verbose=None,
):
"""Plot sensors positions.
Expand Down Expand Up @@ -1074,6 +1076,10 @@ def plot_sensors(
``kind='3d'``, or ``25`` otherwise.
linewidth : float
The width of the outline. If ``0``, the outline will not be drawn.
cmap : str | instance of matplotlib.colors.Colormap | None
Colormap for coloring ch_groups. Has effect only when ``ch_groups``
is list of list. If None, set to ``matplotlib.rcParams["image.cmap"]``.
Defaults to None.
%(verbose)s
Returns
Expand Down Expand Up @@ -1197,10 +1203,9 @@ def plot_sensors(
color = np.mean(_rgb(x, y, z), axis=0)
color_vals[idx, :3] = color # mean of spatial color
else: # array-like
import matplotlib.pyplot as plt

cmap = _get_cmap(cmap)
colors = np.linspace(0, 1, len(ch_groups))
color_vals = [plt.cm.jet(colors[i]) for i in range(len(ch_groups))]
color_vals = [cmap(colors[i]) for i in range(len(ch_groups))]
colors = np.zeros((len(picks), 4))
for pick_idx, pick in enumerate(picks):
for ind, value in enumerate(ch_groups):
Expand Down

0 comments on commit a8ec5d0

Please sign in to comment.