-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
FIX: Improve channel name rendering in plot_alignment
#13773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
afe6247
a9eca8f
6ab310d
11462b9
e834a28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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`_. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have concerns about circumventing mne.viz.backends._pyvista.PyVistaRenderer.text3d and reaching straight for mne-python/mne/viz/backends/_pyvista.py Lines 755 to 756 in ba12118
@drammock WDYT?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for PyVista questions I always ask @larsoner 😆 But looking at the PyVista docs, I don't see any indication that add_point_labels is especially low-level or dangerous. That said, I agree that since we seem to have taken pains to add a wrapper for it, it was probably for a good reason and we should probably use the wrapper.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK! - my specific concern is just that here we hardcode @aman-coder03 is there a specific reason why we need to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @scott-huberty good point...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM |
||||||
| render=False, | ||||||
| reset_camera=False, | ||||||
| ) | ||||||
|
|
||||||
| if src is not None: | ||||||
| atlas_ids, colors = read_freesurfer_lut() | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.