From ae48e8f6cfe725a40473e84c63f35895a6d6c2e4 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Tue, 30 Dec 2025 13:04:21 +0530 Subject: [PATCH 1/9] 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 99864d0d2a7adf39cf5e928c853e2243d502edeb 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/9] [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 3e575f77afeba7d279ebba0cdae6fb8ee34a7ed2 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Fri, 2 Jan 2026 22:02:01 +0530 Subject: [PATCH 3/9] DOC: enchance towncrier and implement show_channel_names in example --- doc/changes/dev/13570.enhancement.rst | 5 +++++ examples/visualization/eeg_on_scalp.py | 1 + mne/viz/_3d.py | 4 +--- 3 files changed, 7 insertions(+), 3 deletions(-) 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..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..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 d0a70b85fb6a7566c8a63071f7f1c0c7b306bd87 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 Jan 2026 14:06:58 +0000 Subject: [PATCH 4/9] [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 From d9e8081de01a464491ba8e8472f031b43d2756d2 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Wed, 21 Jan 2026 19:39:17 +0530 Subject: [PATCH 5/9] DOC: fix towncrier entry for plot_alignment feature --- doc/changes/dev/{13570.enhancement.rst => 13570.newfeature.rst} | 2 +- doc/changes/names.inc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) rename doc/changes/dev/{13570.enhancement.rst => 13570.newfeature.rst} (69%) diff --git a/doc/changes/dev/13570.enhancement.rst b/doc/changes/dev/13570.newfeature.rst similarity index 69% rename from doc/changes/dev/13570.enhancement.rst rename to doc/changes/dev/13570.newfeature.rst index 64956b21fcd..bfca8e73341 100644 --- a/doc/changes/dev/13570.enhancement.rst +++ b/doc/changes/dev/13570.newfeature.rst @@ -2,4 +2,4 @@ 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`. +By :newcontrib:`Aman Srivastava`. (:pr:`13570`) diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 6b58afd6960..4f7f1289ac6 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -14,6 +14,7 @@ .. _Alex Rockhill: https://github.com/alexrockhill/ .. _Alexander Rudiuk: https://github.com/ARudiuk .. _Alexandre Barachant: https://alexandre.barachant.org +.. _Aman Srivastava: https://github.com/aman-coder03 .. _Andrea Brovelli: https://brovelli.github.io/ .. _Andreas Hojlund: https://github.com/ahoejlund .. _Andres Rodriguez: https://github.com/infinitejest/ From 82565636d0e96f7c70786a8880a980c5b7d9cd2c Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Wed, 21 Jan 2026 19:42:36 +0530 Subject: [PATCH 6/9] DOC: fix towncrier role for PR reference --- doc/changes/dev/13570.newfeature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/dev/13570.newfeature.rst b/doc/changes/dev/13570.newfeature.rst index bfca8e73341..56ed64e65bf 100644 --- a/doc/changes/dev/13570.newfeature.rst +++ b/doc/changes/dev/13570.newfeature.rst @@ -2,4 +2,4 @@ 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. -By :newcontrib:`Aman Srivastava`. (:pr:`13570`) +By :newcontrib:`Aman Srivastava`. (:gh:`13570`) From 4fe94541bc0245ed8a7c20d0b3bdd7f202bb5bd9 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 12 Feb 2026 09:53:08 -0600 Subject: [PATCH 7/9] Apply suggestions from code review --- doc/changes/dev/13570.newfeature.rst | 4 +--- mne/viz/_3d.py | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/changes/dev/13570.newfeature.rst b/doc/changes/dev/13570.newfeature.rst index 56ed64e65bf..284614e1b9e 100644 --- a/doc/changes/dev/13570.newfeature.rst +++ b/doc/changes/dev/13570.newfeature.rst @@ -1,5 +1,3 @@ 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. - -By :newcontrib:`Aman Srivastava`. (:gh:`13570`) +locations in the 3D alignment view, by :newcontrib:`Aman Srivastava`. diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index 0de6aade275..466d470bea2 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -647,10 +647,13 @@ def plot_alignment( .. versionchanged:: 1.6 Support for passing a ``dict`` was added. %(sensor_scales)s + .. versionadded:: 1.9 + show_channel_names : bool If True, overlay channel names at sensor locations. Default is False. - .. versionadded:: 1.9 + + .. versionadded:: 1.12 %(verbose)s Returns From 0fba691574a9ff8a6018a5f9fa4e9b0684274a55 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 12 Feb 2026 10:18:56 -0600 Subject: [PATCH 8/9] Apply suggestions from code review --- mne/viz/_3d.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index 466d470bea2..8ef41a526d4 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -647,13 +647,13 @@ def plot_alignment( .. versionchanged:: 1.6 Support for passing a ``dict`` was added. %(sensor_scales)s - .. versionadded:: 1.9 + .. versionadded:: 1.9 show_channel_names : bool If True, overlay channel names at sensor locations. Default is False. - .. versionadded:: 1.12 + .. versionadded:: 1.12 %(verbose)s Returns From 149c5185499fa2f931742bd8b33f7895e1adc40e Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 12 Feb 2026 10:41:25 -0600 Subject: [PATCH 9/9] whitespace --- mne/viz/_3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index 8ef41a526d4..080fb69d71f 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -647,8 +647,8 @@ def plot_alignment( .. versionchanged:: 1.6 Support for passing a ``dict`` was added. %(sensor_scales)s - .. versionadded:: 1.9 + .. versionadded:: 1.9 show_channel_names : bool If True, overlay channel names at sensor locations. Default is False.