Skip to content

Commit e747054

Browse files
committed
Add example plot_fmri_stats_map.py
1 parent e81c5cb commit e747054

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""
2+
Display a volumetric fmri-stats map across the brain surface
3+
=============================================================
4+
5+
This example script does the following:
6+
1) Download a nifti file from nilearn data set
7+
2) Resample it on visbrain BrainObj
8+
3) Plot it in a thresholded fashion
9+
10+
Inspired by nilearn.plotting.plot_surf_stat_map
11+
12+
"""
13+
14+
from visbrain.objects import BrainObj, ColorbarObj, SceneObj
15+
from nilearn import datasets, surface
16+
17+
sc = SceneObj(bgcolor='black', size=(1000, 500))
18+
19+
# Colorbar default arguments
20+
CBAR_STATE = dict(cbtxtsz=20, txtsz=20., width=.1, cbtxtsh=3.,
21+
rect=(-.3, -2., 1., 4.))
22+
KW = dict(title_size=14., zoom=1.2)
23+
24+
motor_images = datasets.fetch_neurovault_motor_task()
25+
stat_img = motor_images.images[0]
26+
# stat_img is a nifti file: "image_10426.nii.gz"
27+
28+
b_obj = BrainObj('white',
29+
translucent=False)
30+
31+
mesh = [b_obj.vertices, b_obj.faces]
32+
33+
# resample from nifti to mesh
34+
texture = surface.vol_to_surf(stat_img, mesh)
35+
36+
# plot mesh across brain oject
37+
b_obj.add_activation(-1 * texture,
38+
cmap='Blues_r',
39+
clim=(1, 7.9),
40+
vmin=1,
41+
vmax=7.9,
42+
hide_under=1,)
43+
44+
cb_proj = ColorbarObj(b_obj,
45+
cblabel='stats map (-)',
46+
cmap='Blues',
47+
vmin=-7.9,
48+
vmax=-1,
49+
clim=(-7.9, -1),
50+
#over='gainsboro',
51+
**CBAR_STATE)
52+
53+
b_obj.add_activation(texture,
54+
cmap='Reds_r',
55+
vmin=1,
56+
vmax=7.9,
57+
clim=(1, 7.9),
58+
hide_under=1)
59+
60+
cb_proj_2 = ColorbarObj(b_obj,
61+
cblabel='statsmap (+)',
62+
cmap='Reds_r',
63+
vmin = 1,
64+
vmax=7.9,
65+
#under='gainsboro',
66+
**CBAR_STATE)
67+
68+
sc.add_to_subplot(b_obj, row=0, col=0, rotate='right')
69+
70+
sc.add_to_subplot(cb_proj,
71+
row=0, col=1,
72+
width_max=200)
73+
74+
sc.add_to_subplot(cb_proj_2,
75+
row=0, col=2,
76+
width_max=200)
77+
78+
sc.preview()

0 commit comments

Comments
 (0)