@@ -975,7 +975,7 @@ def cifti_surfaces_plot(
975
975
surface_type = "inflated" ,
976
976
clip_range = (0 , None ),
977
977
output_file = None ,
978
- ** splt_kwargs ,
978
+ ** kwargs ,
979
979
):
980
980
"""
981
981
Plots a CIFTI-2 dense timeseries onto left/right mesh surfaces.
@@ -995,8 +995,8 @@ def cifti_surfaces_plot(
995
995
output_file: :obj:`str` or :obj:`None`
996
996
Path where the output figure should be saved. If this is not defined,
997
997
then the figure will be returned.
998
- splt_kwargs : dict
999
- Keyword arguments for :obj:`surfplot.Plot `
998
+ kwargs : dict
999
+ Keyword arguments for :obj:`nilearn.plotting.plot_surf `
1000
1000
1001
1001
Outputs
1002
1002
-------
@@ -1005,8 +1005,7 @@ def cifti_surfaces_plot(
1005
1005
output_file: :obj:`str`
1006
1006
The file where the figure is saved.
1007
1007
"""
1008
- import surfplot as splt
1009
- from surfplot .utils import add_fslr_medial_wall
1008
+ from nilearn .plotting import plot_surf
1010
1009
1011
1010
def get_surface_meshes (density , surface_type ):
1012
1011
import templateflow .api as tf
@@ -1036,28 +1035,67 @@ def get_surface_meshes(density, surface_type):
1036
1035
# as potential nonsteady states
1037
1036
data = img .dataobj [5 :20 ].mean (axis = 0 )
1038
1037
1039
- cortex_data = _concat_brain_struct_data (( left_cortex , right_cortex ), data )
1040
- if density == "32k" and len ( cortex_data ) != 59412 :
1038
+ counts = ( left_cortex . index_count , right_cortex . index_count )
1039
+ if density == "32k" and counts != ( 29696 , 29716 ) :
1041
1040
raise ValueError ("Cortex data is not in fsLR space" )
1041
+
1042
1042
# medial wall needs to be added back in
1043
- cortex_data = add_fslr_medial_wall (cortex_data )
1043
+ lh_data = np .full (left_cortex .surface_number_of_vertices , np .nan )
1044
+ rh_data = np .full (right_cortex .surface_number_of_vertices , np .nan )
1045
+ lh_data [left_cortex .vertex_indices ] = _concat_brain_struct_data ([left_cortex ], data )
1046
+ rh_data [right_cortex .vertex_indices ] = _concat_brain_struct_data ([right_cortex ], data )
1047
+
1044
1048
if clip_range :
1045
- cortex_data = np .clip (cortex_data , clip_range [0 ], clip_range [1 ], out = cortex_data )
1049
+ lh_data = np .clip (lh_data , clip_range [0 ], clip_range [1 ], out = lh_data )
1050
+ rh_data = np .clip (rh_data , clip_range [0 ], clip_range [1 ], out = rh_data )
1051
+ mn , mx = clip_range
1052
+ else :
1053
+ mn , mx = None , None
1046
1054
1047
- lh_data , rh_data = np .array_split (cortex_data , 2 )
1055
+ if mn is None :
1056
+ mn = np .min (data )
1057
+ if mx is None :
1058
+ mx = np .max (data )
1059
+
1060
+ cmap = kwargs .pop ('cmap' , 'YlOrRd_r' )
1061
+ cbar_map = cm .ScalarMappable (norm = Normalize (mn , mx ), cmap = cmap )
1062
+
1063
+ # Make background maps that rescale to a medium gray
1064
+ lh_bg = np .zeros (lh_data .shape , 'int8' )
1065
+ rh_bg = np .zeros (rh_data .shape , 'int8' )
1066
+ lh_bg [:2 ] = [3 , - 2 ]
1067
+ rh_bg [:2 ] = [3 , - 2 ]
1048
1068
1049
- # Build the figure
1050
1069
lh_mesh , rh_mesh = get_surface_meshes (density , surface_type )
1051
- p = splt .Plot (
1052
- surf_lh = lh_mesh , surf_rh = rh_mesh , layout = splt_kwargs .pop ("layout" , "row" ), ** splt_kwargs
1053
- )
1054
- p .add_layer ({'left' : lh_data , 'right' : rh_data }, cmap = 'YlOrRd_r' )
1055
- figure = p .build () # figsize - leave default?
1070
+ lh_kwargs = dict (surf_mesh = lh_mesh , surf_map = lh_data , bg_map = lh_bg )
1071
+ rh_kwargs = dict (surf_mesh = rh_mesh , surf_map = rh_data , bg_map = rh_bg )
1072
+
1073
+ # Build the figure
1074
+ figure = plt .figure (figsize = plt .figaspect (0.25 ), constrained_layout = True )
1075
+ for i , view in enumerate (('lateral' , 'medial' )):
1076
+ for j , hemi in enumerate (('left' , 'right' )):
1077
+ title = f'{ hemi .title ()} - { view .title ()} '
1078
+ ax = figure .add_subplot (1 , 4 , i * 2 + j + 1 , projection = '3d' , rasterized = True )
1079
+ hemi_kwargs = (lh_kwargs , rh_kwargs )[j ]
1080
+ plot_surf (
1081
+ hemi = hemi ,
1082
+ view = view ,
1083
+ title = title ,
1084
+ cmap = cmap ,
1085
+ vmin = mn ,
1086
+ vmax = mx ,
1087
+ axes = ax ,
1088
+ ** hemi_kwargs ,
1089
+ ** kwargs
1090
+ )
1091
+ # plot_surf sets this to 8, which seems a little far out, but 6 starts clipping
1092
+ ax .dist = 7
1093
+
1094
+ figure .colorbar (cbar_map , shrink = 0.2 , ax = figure .axes , location = 'bottom' )
1056
1095
1057
1096
if output_file is not None :
1058
- figure .savefig (output_file , bbox_inches = "tight" )
1097
+ figure .savefig (output_file , bbox_inches = "tight" , dpi = 400 )
1059
1098
plt .close (figure )
1060
- figure = None
1061
1099
return output_file
1062
1100
1063
1101
return figure
0 commit comments