diff --git a/doc/changes/dev/13570.enhancement.rst b/doc/changes/dev/13570.enhancement.rst new file mode 100644 index 00000000000..64956b21fcd --- /dev/null +++ b/doc/changes/dev/13570.enhancement.rst @@ -0,0 +1,5 @@ +Add an optional ``show_channel_names`` parameter to +:meth:`mne.viz.plot_alignment` to overlay channel labels at sensor +locations in the 3D alignment view. + +Contributed by Aman Srivastava (:gh:`aman-coder03`) in :pr:`13570`. diff --git a/examples/visualization/eeg_on_scalp.py b/examples/visualization/eeg_on_scalp.py index f3201bd39f1..1146ae229ef 100644 --- a/examples/visualization/eeg_on_scalp.py +++ b/examples/visualization/eeg_on_scalp.py @@ -35,6 +35,7 @@ meg=[], coord_frame="head", subjects_dir=subjects_dir, + show_channel_names=True, ) # Set viewing angle diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index cc660fe4986..0de6aade275 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -554,6 +554,7 @@ def plot_alignment( sensor_colors=None, *, sensor_scales=None, + show_channel_names=False, verbose=None, ): """Plot head, sensor, and source space alignment in 3D. @@ -646,7 +647,9 @@ def plot_alignment( .. versionchanged:: 1.6 Support for passing a ``dict`` was added. %(sensor_scales)s - + show_channel_names : bool + If True, overlay channel names at sensor locations. + Default is False. .. versionadded:: 1.9 %(verbose)s @@ -942,6 +945,23 @@ def plot_alignment( sensor_scales=sensor_scales, ) + if show_channel_names and picks.size > 0: + chs = [info["chs"][pi] for pi in picks] + + # channel positions are in head coordinates + pos = np.array([ch["loc"][:3] for ch in chs]) + + # transform to current coord frame + pos = apply_trans(to_cf_t["head"], pos) + + for ch, xyz in zip(chs, pos): + renderer.text3d( + *xyz, + ch["ch_name"], + scale=0.005, + color=(1.0, 1.0, 1.0), + ) + if src is not None: atlas_ids, colors = read_freesurfer_lut() for ss in src: