1111from mpl_toolkits .mplot3d import Axes3D # noqa
1212import nibabel as nib
1313import numpy as np
14- from scipy .stats import zscore
1514
1615from .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 :
0 commit comments