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 , custom_aspect = True , cbar = False ,
730- figsize = (4 , 4.8 ), robust = True , size = 50 , ** kwargs ):
728+ def plot_point_brain (data , coords , views = None , views_orientation = 'vertical' ,
729+ cbar = False , figsize = (4 , 4.8 ), 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,9 @@ def plot_point_brain(data, coords, views=None, custom_aspect=True, cbar=False,
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- custom_aspect: bool, optional
745- Whether to use a custom aspect ratio, specifically set to visualize
746- brain data, but that deforms the data, or automatically scale axes to
747- have an 'equal' aspect ratios. Default: True
744+ views_orientation: str, optional
745+ Orientation of the views. Can be either 'vertical' or 'horizontal'.
746+ Default: 'vertical'.
748747 cbar : bool, optional
749748 Whether to also show colorbar. Default: False
750749 figsize : tuple, optional
@@ -765,10 +764,6 @@ def plot_point_brain(data, coords, views=None, custom_aspect=True, cbar=False,
765764 axial = (90 , 180 ), ax = (90 , 180 ),
766765 coronal = (0 , 90 ), cor = (0 , 90 ))
767766
768- # coordinate space needs to be centered around zero for custom aspect ratio
769- if custom_aspect :
770- coords = zscore (coords )
771-
772767 x , y , z = coords [:, 0 ], coords [:, 1 ], coords [:, 2 ]
773768
774769 if views is None :
@@ -778,8 +773,13 @@ def plot_point_brain(data, coords, views=None, custom_aspect=True, cbar=False,
778773 views = [views ]
779774 views = [_views [f ] for f in views ]
780775
776+ if views_orientation == 'vertical' :
777+ ncols , nrows = 1 , len (views )
778+ elif views_orientation == 'horizontal' :
779+ ncols , nrows = len (views ), 1
780+
781781 # create figure and axes (3d projections)
782- fig , axes = plt .subplots (ncols = 1 , nrows = len ( views ) ,
782+ fig , axes = plt .subplots (ncols = ncols , nrows = nrows ,
783783 figsize = figsize ,
784784 subplot_kw = dict (projection = '3d' ))
785785
@@ -797,21 +797,12 @@ def plot_point_brain(data, coords, views=None, custom_aspect=True, cbar=False,
797797 col = ax .scatter (x , y , z , c = data , s = size , ** opts )
798798 ax .view_init (* view )
799799 ax .axis ('off' )
800+ scaling = np .array ([ax .get_xlim (),
801+ ax .get_ylim (),
802+ ax .get_zlim ()])
803+ ax .set_box_aspect (tuple (scaling [:, 1 ] - scaling [:, 0 ]))
800804
801- # if aspect is custom, manually set limits to the values we want
802- if custom_aspect :
803- ax .set (xlim = 0.665 * np .array (ax .get_xlim ()),
804- ylim = 0.665 * np .array (ax .get_ylim ()),
805- zlim = 0.70 * np .array (ax .get_zlim ()))
806-
807- # otherwise, automatically scale axes to have 'equal' aspect ratios
808- else :
809- scaling = np .array ([ax .get_xlim (),
810- ax .get_ylim (),
811- ax .get_zlim ()])
812- ax .auto_scale_xyz (* [[np .min (scaling ), np .max (scaling )]] * 3 )
813-
814- fig .subplots_adjust (left = 0 , right = 1 , bottom = 0 , top = 1 , hspace = 0 )
805+ fig .subplots_adjust (left = 0 , right = 1 , bottom = 0 , top = 1 , hspace = 0 , wspace = 0 )
815806
816807 # add colorbar to axes
817808 if cbar :
0 commit comments