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/mne/viz/_3d.py b/mne/viz/_3d.py index 585cd81de2f..4ac4936e40a 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -955,13 +955,27 @@ def plot_alignment( # 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), - ) + # offset labels outward from centroid so they clear the sensor glyphs + centroid = pos.mean(axis=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="renderer.font_family", + 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()