Skip to content

Commit fbdf9a3

Browse files
authored
Merge pull request #104 from VinceBaz/fix_plot_point_brain
2 parents 46fdb31 + 4f4d8b8 commit fbdf9a3

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

netneurotools/plotting.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from mpl_toolkits.mplot3d import Axes3D # noqa
1212
import nibabel as nib
1313
import numpy as np
14-
from scipy.stats import zscore
1514

1615
from .freesurfer import FSIGNORE, _decode_list
1716

@@ -726,8 +725,9 @@ def plot_fsvertex(data, *, order='lr', surf='pial', views='lat',
726725
return brain
727726

728727

729-
def plot_point_brain(data, coords, views=None, cbar=False, figsize=(4, 4.8),
730-
robust=True, size=50, **kwargs):
728+
def plot_point_brain(data, coords, views=None, views_orientation='vertical',
729+
views_size=(4, 2.4), cbar=False, robust=True, size=50,
730+
**kwargs):
731731
"""
732732
Plots `data` as a cloud of points in 3D space based on specified `coords`
733733
@@ -741,10 +741,13 @@ def plot_point_brain(data, coords, views=None, cbar=False, figsize=(4, 4.8),
741741
List specifying which views to use. Can be any of {'sagittal', 'sag',
742742
'coronal', 'cor', 'axial', 'ax'}. If not specified will use 'sagittal'
743743
and 'axial'. Default: None
744+
views_orientation: str, optional
745+
Orientation of the views. Can be either 'vertical' or 'horizontal'.
746+
Default: 'vertical'.
747+
views_size : tuple, optional
748+
Figure size of each view. Default: (4, 2.4)
744749
cbar : bool, optional
745750
Whether to also show colorbar. Default: False
746-
figsize : tuple, optional
747-
Figure size. Default: (4, 4.8)
748751
robust : bool, optional
749752
Whether to use robust calculation of `vmin` and `vmax` for color scale.
750753
size : int, optional
@@ -761,18 +764,23 @@ def plot_point_brain(data, coords, views=None, cbar=False, figsize=(4, 4.8),
761764
axial=(90, 180), ax=(90, 180),
762765
coronal=(0, 90), cor=(0, 90))
763766

764-
# coordinate space needs to be centered around zero for aspect ratio
765-
coords = zscore(coords)
766767
x, y, z = coords[:, 0], coords[:, 1], coords[:, 2]
768+
767769
if views is None:
768770
views = [_views[f] for f in ['sagittal', 'axial']]
769771
else:
770772
if not isinstance(views, Iterable) or isinstance(views, str):
771773
views = [views]
772774
views = [_views[f] for f in views]
773775

776+
if views_orientation == 'vertical':
777+
ncols, nrows = 1, len(views)
778+
elif views_orientation == 'horizontal':
779+
ncols, nrows = len(views), 1
780+
figsize = (ncols * views_size[0], nrows * views_size[1])
781+
774782
# create figure and axes (3d projections)
775-
fig, axes = plt.subplots(ncols=1, nrows=len(views),
783+
fig, axes = plt.subplots(ncols=ncols, nrows=nrows,
776784
figsize=figsize,
777785
subplot_kw=dict(projection='3d'))
778786

@@ -790,10 +798,12 @@ def plot_point_brain(data, coords, views=None, cbar=False, figsize=(4, 4.8),
790798
col = ax.scatter(x, y, z, c=data, s=size, **opts)
791799
ax.view_init(*view)
792800
ax.axis('off')
793-
ax.set(xlim=0.57 * np.array(ax.get_xlim()),
794-
ylim=0.57 * np.array(ax.get_ylim()),
795-
zlim=0.60 * np.array(ax.get_zlim()))
796-
fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
801+
scaling = np.array([ax.get_xlim(),
802+
ax.get_ylim(),
803+
ax.get_zlim()])
804+
ax.set_box_aspect(tuple(scaling[:, 1] - scaling[:, 0]))
805+
806+
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0, wspace=0)
797807

798808
# add colorbar to axes
799809
if cbar:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ nilearn
55
numpy>=1.16
66
scikit-learn
77
scipy>=1.4.0
8+
matplotlib>=3.3.0
89
tqdm

tools/install_dependencies.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if [ -n "${OPTIONAL_DEPENDS}" ]; then
99
for DEP in ${OPTIONAL_DEPENDS}; do
1010
if [ ${DEP} == "mayavi" ]; then
1111
python -m pip install numpy vtk
12+
sudo apt update
1213
sudo apt-get install -y xvfb \
1314
x11-utils \
1415
mencoder \

0 commit comments

Comments
 (0)