Skip to content
5 changes: 5 additions & 0 deletions doc/changes/dev/13570.enhancement.rst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take a look at other files in this directory, to see how they should be formatted (e.g. no heading, and mention the author and PR number)

Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions examples/visualization/eeg_on_scalp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
meg=[],
coord_frame="head",
subjects_dir=subjects_dir,
show_channel_names=True,
)

# Set viewing angle
Expand Down
22 changes: 21 additions & 1 deletion mne/viz/_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
Loading