From 0d9cfeb9a0b0d721870a6af4f52797067fedd968 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Tue, 30 Dec 2025 13:04:21 +0530 Subject: [PATCH 1/6] ENH: Add optional channel name overlay to plot_alignment --- mne/viz/_3d.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index cc660fe4986..d9ea4cb1ebf 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 @@ -941,6 +944,25 @@ def plot_alignment( sensor_colors=sensor_colors, 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[0], + xyz[1], + xyz[2], + ch["ch_name"], + scale=0.005, + color=(1.0, 1.0, 1.0), + ) if src is not None: atlas_ids, colors = read_freesurfer_lut() From c3105cea20abbfb8b3fb00c77cb2921a7fd4d5a8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Dec 2025 07:37:07 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/viz/_3d.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index d9ea4cb1ebf..f98346aeb0f 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -944,10 +944,10 @@ def plot_alignment( sensor_colors=sensor_colors, sensor_scales=sensor_scales, ) - + if show_channel_names and picks.size > 0: - chs = [info["chs"][pi] for pi in picks] - + chs = [info["chs"][pi] for pi in picks] + # channel positions are in head coordinates pos = np.array([ch["loc"][:3] for ch in chs]) From e1ca99f0c2a6e8f02e3351c5253c196d3953b70e Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Tue, 30 Dec 2025 13:10:12 +0530 Subject: [PATCH 3/6] DOC: Add towncrier entry for plot_alignment channel labels --- doc/changes/dev/13570.enhancement.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/changes/dev/13570.enhancement.rst diff --git a/doc/changes/dev/13570.enhancement.rst b/doc/changes/dev/13570.enhancement.rst new file mode 100644 index 00000000000..f610ed1f4dd --- /dev/null +++ b/doc/changes/dev/13570.enhancement.rst @@ -0,0 +1,6 @@ +Enhancement +----------- + +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. From c8c81a9dc174cd7e636ed32af18e3e3c2df2d249 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Tue, 30 Dec 2025 13:15:30 +0530 Subject: [PATCH 4/6] DOC: Add towncrier entry for plot_alignment channel labels --- doc/changes/dev/13570.enhancement.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changes/dev/13570.enhancement.rst b/doc/changes/dev/13570.enhancement.rst index f610ed1f4dd..4185560962b 100644 --- a/doc/changes/dev/13570.enhancement.rst +++ b/doc/changes/dev/13570.enhancement.rst @@ -4,3 +4,4 @@ Enhancement 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. + From 58c9b10d1885019da5bd5885a03346f52348db64 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Fri, 2 Jan 2026 22:02:01 +0530 Subject: [PATCH 5/6] DOC: enchance towncrier and implement show_channel_names in example --- doc/changes/dev/13570.enhancement.rst | 4 +--- examples/visualization/eeg_on_scalp.py | 1 + mne/viz/_3d.py | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/changes/dev/13570.enhancement.rst b/doc/changes/dev/13570.enhancement.rst index 4185560962b..64956b21fcd 100644 --- a/doc/changes/dev/13570.enhancement.rst +++ b/doc/changes/dev/13570.enhancement.rst @@ -1,7 +1,5 @@ -Enhancement ------------ - 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..4f11a4cbe4c 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 f98346aeb0f..0de6aade275 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -956,9 +956,7 @@ def plot_alignment( for ch, xyz in zip(chs, pos): renderer.text3d( - xyz[0], - xyz[1], - xyz[2], + *xyz, ch["ch_name"], scale=0.005, color=(1.0, 1.0, 1.0), From 3a59872425cf61159fd69ac1d76cb07ddd935046 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 2 Jan 2026 16:32:31 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/visualization/eeg_on_scalp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/visualization/eeg_on_scalp.py b/examples/visualization/eeg_on_scalp.py index 4f11a4cbe4c..1146ae229ef 100644 --- a/examples/visualization/eeg_on_scalp.py +++ b/examples/visualization/eeg_on_scalp.py @@ -35,7 +35,7 @@ meg=[], coord_frame="head", subjects_dir=subjects_dir, - show_channel_names=True + show_channel_names=True, ) # Set viewing angle