Skip to content

Commit 21d517a

Browse files
Merge pull request #219 from naplab/brain_plot-views
Enhance brain view modes with 'occipital', 'bottom', and custom views
2 parents 4a7745f + 35937cd commit 21d517a

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

naplib/visualization/brain_plots.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def _view(hemi, mode: str = "lateral", backend: str = "mpl"):
1818
---------
1919
hemi : {'lh','rh'}
2020
Hemisphere
21-
mode : {'lateral','medial','frontal','top','best'}, default='lateral'
21+
mode : {'lateral','medial','frontal','occipital',top','bottom',best'}, default='lateral'
2222
What view to return azimuth and elevation for. One of 'lateral',
23-
'best', 'medial','frontal','top'
23+
'best', 'medial','frontal','occipital',top','bottom'
2424
backend : {'mpl','plotly'}, defualt='mpl'
2525
Plotting backend, either 'mpl' or 'plotly'
2626
@@ -55,6 +55,14 @@ def _view(hemi, mode: str = "lateral", backend: str = "mpl"):
5555
else:
5656
return (0, 90)
5757

58+
elif mode == "occipital":
59+
if backend == "plotly":
60+
eye = dict(x=0, y=-1, z=0)
61+
center = dict(x=0, y=0, z=0)
62+
return eye, center
63+
else:
64+
return (0, 270)
65+
5866
elif mode == "top":
5967
if backend == "plotly":
6068
eye = dict(x=0, y=0, z=1)
@@ -63,6 +71,14 @@ def _view(hemi, mode: str = "lateral", backend: str = "mpl"):
6371
else:
6472
return (90, 270)
6573

74+
elif mode == "bottom":
75+
if backend == "plotly":
76+
eye = dict(x=0, y=0, z=-1)
77+
center = dict(x=0, y=0, z=0)
78+
return eye, center
79+
else:
80+
return (270, 270)
81+
6682
elif mode == "best":
6783
if backend == "plotly":
6884
eye = dict(x=-1, y=0.1, z=0.1) if hemi == "lh" else dict(x=1, y=0.1, z=0.1)
@@ -75,10 +91,15 @@ def _view(hemi, mode: str = "lateral", backend: str = "mpl"):
7591

7692

7793
def _plot_hemi(hemi, cmap="coolwarm", ax=None, view="best", threshold=None, vmin=None, vmax=None):
94+
if isinstance(view, tuple):
95+
elev, azim = view
96+
else:
97+
elev, azim = _view(hemi.hemi, mode=view)
98+
7899
surfdist_viz(
79100
*hemi.surf,
80101
hemi.overlay,
81-
*_view(hemi.hemi, mode=view),
102+
elev, azim,
82103
cmap=cmap,
83104
threshold=threshold,
84105
alpha=hemi.alpha,
@@ -111,8 +132,10 @@ def plot_brain_overlay(
111132
hemi : {'both', 'lh', 'rh'}, default='both'
112133
Hemisphere(s) to plot. If 'both', then 2 subplots are created, one for each hemisphere.
113134
Otherwise only one hemisphere is displayed with its overlay.
114-
view : {'lateral','medial','frontal','top','best'}, default='best'
115-
Which view to plot for each hemisphere.
135+
view : {'lateral','medial','frontal','occipital',top','bottom',best'} | tuple, default='best'
136+
View of the brain to display. A tuple can specify the (elevation, azimuth) for matplotlib backend,
137+
or a tuple of dicts for (eye, center), which are the plotly.graph_objects.layout.scene.camera.eye and
138+
plotly.graph_objects.layout.scene.camera.center for plotly backend.
116139
vmin : float, optional
117140
Minimum value for colormap. If not given, will use cmap_quantile or range or overlay values.
118141
vmax : float, optional
@@ -302,7 +325,7 @@ def plot_brain_elecs(
302325
hemi : {'both', 'lh', 'rh'}, default='both'
303326
Hemisphere(s) to plot. If 'both', then 2 subplots are created, one for each hemisphere.
304327
Otherwise only one hemisphere is displayed with its electrodes.
305-
view : {'lateral','frontal','medial','top','best'} | tuple, default='lateral'
328+
view : {'lateral','frontal','occipital',medial','top','bottom',best'} | tuple, default='lateral'
306329
View of the brain to display. A tuple can specify the (elevation, azimuth) for matplotlib backend,
307330
or a tuple of dicts for (eye, center), which are the plotly.graph_objects.layout.scene.camera.eye and
308331
plotly.graph_objects.layout.scene.camera.center for plotly backend.

0 commit comments

Comments
 (0)