Skip to content

Commit 29f1686

Browse files
committed
FIX: Use nilearn plot_surf over surfplot
1 parent 5f2dc27 commit 29f1686

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

niworkflows/viz/plots.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,7 @@ def cifti_surfaces_plot(
10051005
output_file: :obj:`str`
10061006
The file where the figure is saved.
10071007
"""
1008-
import surfplot as splt
1009-
from surfplot.utils import add_fslr_medial_wall
1008+
from nilearn.plotting import plot_surf
10101009

10111010
def get_surface_meshes(density, surface_type):
10121011
import templateflow.api as tf
@@ -1036,28 +1035,31 @@ def get_surface_meshes(density, surface_type):
10361035
# as potential nonsteady states
10371036
data = img.dataobj[5:20].mean(axis=0)
10381037

1039-
cortex_data = _concat_brain_struct_data((left_cortex, right_cortex), data)
1040-
if density == "32k" and len(cortex_data) != 59412:
1038+
if density == "32k" and len(data) != 91282:
10411039
raise ValueError("Cortex data is not in fsLR space")
1040+
10421041
# medial wall needs to be added back in
1043-
cortex_data = add_fslr_medial_wall(cortex_data)
1044-
if clip_range:
1045-
cortex_data = np.clip(cortex_data, clip_range[0], clip_range[1], out=cortex_data)
1042+
lh_data = np.full(max(left_cortex.vertex_indices) + 1, np.nan)
1043+
rh_data = np.full(max(right_cortex.vertex_indices) + 1, np.nan)
1044+
lh_data[left_cortex.vertex_indices] = _concat_brain_struct_data([left_cortex], data)
1045+
rh_data[right_cortex.vertex_indices] = _concat_brain_struct_data([right_cortex], data)
10461046

1047-
lh_data, rh_data = np.array_split(cortex_data, 2)
1047+
if clip_range:
1048+
lh_data = np.clip(lh_data, clip_range[0], clip_range[1], out=lh_data)
1049+
rh_data = np.clip(rh_data, clip_range[0], clip_range[1], out=rh_data)
10481050

10491051
# Build the figure
10501052
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?
1053+
figure = plt.figure(figsize=plt.figaspect(0.5))
1054+
ax0 = figure.add_subplot(1, 2, 1, projection='3d')
1055+
plot_surf(lh_mesh, lh_data, cmap='YlOrRd_r', axes=ax0)
1056+
ax1 = figure.add_subplot(1, 2, 2, projection='3d')
1057+
plot_surf(lh_mesh, lh_data, cmap='YlOrRd_r', axes=ax1)
10561058

10571059
if output_file is not None:
10581060
figure.savefig(output_file, bbox_inches="tight")
10591061
plt.close(figure)
1060-
figure = None
1062+
del figure
10611063
return output_file
10621064

10631065
return figure

0 commit comments

Comments
 (0)