8.2.11. Making a surface plot of a 3D statistical map

project a 3D statistical map onto a cortical mesh using nilearn.surface.vol_to_surf. Display a surface plot of the projected map using nilearn.plotting.plot_surf_stat_map.

8.2.11.1. Get a statistical map

from nilearn import datasets

motor_images = datasets.fetch_neurovault_motor_task()
stat_img = motor_images.images[0]

8.2.11.2. Get a cortical mesh

8.2.11.3. Sample the 3D data around each node of the mesh

from nilearn import surface

texture = surface.vol_to_surf(stat_img, fsaverage.pial_right)

8.2.11.4. Plot the result

from nilearn import plotting

plotting.plot_surf_stat_map(fsaverage.infl_right, texture, hemi='right',
                            title='Surface right hemisphere', colorbar=True,
                            threshold=1., bg_map=fsaverage.sulc_right)
../../_images/sphx_glr_plot_3d_map_to_surface_projection_001.png

8.2.11.5. Plot 3D image for comparison

plotting.plot_glass_brain(stat_img, display_mode='r', plot_abs=False,
                          title='Glass brain', threshold=2.)

plotting.plot_stat_map(stat_img, display_mode='x', threshold=1.,
                       cut_coords=range(0, 51, 10), title='Slices')
  • ../../_images/sphx_glr_plot_3d_map_to_surface_projection_002.png
  • ../../_images/sphx_glr_plot_3d_map_to_surface_projection_003.png

8.2.11.6. Plot with higher-resolution mesh

fetch_surf_fsaverage takes a “mesh” argument which specifies wether to fetch the low-resolution fsaverage5 mesh, or the high-resolution fsaverage mesh. using mesh=”fsaverage” will result in more memory usage and computation time, but finer visualizations.

big_fsaverage = datasets.fetch_surf_fsaverage('fsaverage')
big_texture = surface.vol_to_surf(stat_img, big_fsaverage.pial_right)

plotting.plot_surf_stat_map(big_fsaverage.infl_right,
                            big_texture, hemi='right', colorbar=True,
                            title='Surface right hemisphere: fine mesh',
                            threshold=1., bg_map=big_fsaverage.sulc_right)


plotting.show()
../../_images/sphx_glr_plot_3d_map_to_surface_projection_004.png

8.2.11.7. 3D visualization in a web browser

An alternative to nilearn.plotting.plot_surf_stat_map is to use nilearn.plotting.view_surf or nilearn.plotting.view_img_on_surf that give more interactive visualizations in a web browser. See 3D Plots of statistical maps or atlases on the cortical surface for more details.

view = plotting.view_surf(fsaverage.infl_right, texture, threshold='90%',
                          bg_map=fsaverage.sulc_right)
# uncomment this to open the plot in a web browser:
# view.open_in_browser()

In a Jupyter notebook, if view is the output of a cell, it will be displayed below the cell

view

We don’t need to do the projection ourselves, we can use view_img_on_surf:

view = plotting.view_img_on_surf(stat_img, threshold='90%')
# view.open_in_browser()

view

Total running time of the script: ( 0 minutes 6.491 seconds)

Generated by Sphinx-Gallery