From afe6247524a094107ecf672163c4c8671fa5c258 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sat, 21 Mar 2026 14:38:01 +0530 Subject: [PATCH 1/6] reduce text scale and improve contrast --- mne/viz/_3d.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index 585cd81de2f..ce7ff76ffeb 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -955,12 +955,20 @@ def plot_alignment( # transform to current coord frame pos = apply_trans(to_cf_t["head"], pos) + # compute centroid to determine outward direction for each label + centroid = pos.mean(axis=0) for ch, xyz in zip(chs, pos): + direction = xyz - centroid + norm = np.linalg.norm(direction) + if norm > 0: + offset = xyz + 0.01 * direction / norm + else: + offset = xyz renderer.text3d( - *xyz, + *offset, ch["ch_name"], - scale=0.005, - color=(1.0, 1.0, 1.0), + scale=0.0015, + color=(0.0, 0.0, 0.0), ) if src is not None: From a9eca8f0a237adb11d21a576ef569de8a6bbbc6a Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 22 Mar 2026 12:25:41 +0530 Subject: [PATCH 2/6] switch text color back to white --- 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 ce7ff76ffeb..e3f83661907 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -968,7 +968,7 @@ def plot_alignment( *offset, ch["ch_name"], scale=0.0015, - color=(0.0, 0.0, 0.0), + color=(1.0, 1.0, 1.0), ) if src is not None: From 6ab310dfc4ab73abd31c976c9bc32c62dd7deb38 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 22 Mar 2026 12:31:58 +0530 Subject: [PATCH 3/6] use add_point_labels for show_channel_names --- mne/viz/_3d.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index e3f83661907..11fb6c18cf0 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -955,21 +955,27 @@ def plot_alignment( # transform to current coord frame pos = apply_trans(to_cf_t["head"], pos) - # compute centroid to determine outward direction for each label + # offset labels outward from centroid so they clear the sensor glyphs centroid = pos.mean(axis=0) - for ch, xyz in zip(chs, pos): - direction = xyz - centroid - norm = np.linalg.norm(direction) - if norm > 0: - offset = xyz + 0.01 * direction / norm - else: - offset = xyz - renderer.text3d( - *offset, - ch["ch_name"], - scale=0.0015, - color=(1.0, 1.0, 1.0), - ) + directions = pos - centroid + norms = np.linalg.norm(directions, axis=1, keepdims=True) + norms = np.where(norms > 0, norms, 1) + offsets = pos + 0.01 * directions / norms + + labels = [ch["ch_name"] for ch in chs] + renderer.plotter.add_point_labels( + offsets, + labels, + font_size=10, + text_color=(1.0, 1.0, 1.0), + font_family="arial", + shadow=True, + show_points=False, + shape=None, + always_visible=True, + render=False, + reset_camera=False, + ) if src is not None: atlas_ids, colors = read_freesurfer_lut() From 11462b9bfad57116a2a717ea32c3f5f44f371c96 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Wed, 25 Mar 2026 10:20:09 +0530 Subject: [PATCH 4/6] add changelog entry --- doc/changes/dev/13773.bugfix.rst | 1 + examples/visualization/eeg_on_scalp.py | 1 + 2 files changed, 2 insertions(+) create mode 100644 doc/changes/dev/13773.bugfix.rst diff --git a/doc/changes/dev/13773.bugfix.rst b/doc/changes/dev/13773.bugfix.rst new file mode 100644 index 00000000000..8ddd3300422 --- /dev/null +++ b/doc/changes/dev/13773.bugfix.rst @@ -0,0 +1 @@ +Improved channel name label rendering in :func:`mne.viz.plot_alignment` when using ``show_channel_names=True`` by reducing overlap, adding a shadow for contrast, and offsetting labels outward from sensor positions, by `Aman Srivastava`_. diff --git a/examples/visualization/eeg_on_scalp.py b/examples/visualization/eeg_on_scalp.py index 1146ae229ef..d64ea05c9f2 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 renders readable labels with shadow and outward offset show_channel_names=True, ) From e834a28863f7cedf3cc44dabfc9bd063d7434e37 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Thu, 26 Mar 2026 13:59:57 +0530 Subject: [PATCH 5/6] address review comments --- examples/visualization/eeg_on_scalp.py | 1 - mne/viz/_3d.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/visualization/eeg_on_scalp.py b/examples/visualization/eeg_on_scalp.py index d64ea05c9f2..1146ae229ef 100644 --- a/examples/visualization/eeg_on_scalp.py +++ b/examples/visualization/eeg_on_scalp.py @@ -35,7 +35,6 @@ meg=[], coord_frame="head", subjects_dir=subjects_dir, - # show_channel_names=True renders readable labels with shadow and outward offset show_channel_names=True, ) diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index 11fb6c18cf0..4ac4936e40a 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -968,7 +968,7 @@ def plot_alignment( labels, font_size=10, text_color=(1.0, 1.0, 1.0), - font_family="arial", + font_family="renderer.font_family", shadow=True, show_points=False, shape=None, From 76d76a2a7cbf082f5097f270760b039412fda827 Mon Sep 17 00:00:00 2001 From: Aman Srivastava <160766756+aman-coder03@users.noreply.github.com> Date: Thu, 2 Apr 2026 14:59:45 +0530 Subject: [PATCH 6/6] Update doc/changes/dev/13773.bugfix.rst Co-authored-by: Daniel McCloy --- doc/changes/dev/13773.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/dev/13773.bugfix.rst b/doc/changes/dev/13773.bugfix.rst index 8ddd3300422..1d081ddad48 100644 --- a/doc/changes/dev/13773.bugfix.rst +++ b/doc/changes/dev/13773.bugfix.rst @@ -1 +1 @@ -Improved channel name label rendering in :func:`mne.viz.plot_alignment` when using ``show_channel_names=True`` by reducing overlap, adding a shadow for contrast, and offsetting labels outward from sensor positions, by `Aman Srivastava`_. +Make channel name labels easier to read in :func:`mne.viz.plot_alignment`, by `Aman Srivastava`_.