-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_plot.py
53 lines (38 loc) · 1.76 KB
/
utils_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 18 12:30:29 2021
@author: Leon D. Lotter
"""
from nilearn.plotting import plot_glass_brain
from nilearn.datasets import fetch_surf_fsaverage
from neuromaps.transforms import mni152_to_fsaverage
from surfplot import Plot
def plot_gb(img, title=None, thresh=0, col='RdBu_r'):
"""
Plots volume on a nilearn glass brain.
Input: img=input volume, title=plot title, thresh=plot threshold, col=color
"""
gb = plot_glass_brain(img, title=title, threshold=thresh, draw_cross=False,
cmap=col, display_mode='lyrz')
#=============================================================================
def plot_surf(vol, title='', interp='linear', legend=True, cmap='viridis',
overlay=None, views=['lateral', 'medial'], size=(1000, 250),
flip=False, zoom=1.2):
fsaverage = fetch_surf_fsaverage()
map_lh, map_rh = mni152_to_fsaverage(vol, method=interp, fsavg_density='10k')
p = Plot(surf_lh=fsaverage['pial_left'], surf_rh=fsaverage['pial_right'],
layout='row', size=size, zoom=zoom, views=views, flip=flip)
p.add_layer({'left': map_lh, 'right': map_rh}, cmap=cmap, cbar=legend)
if overlay is not None:
outline_lh, outline_rh = mni152_to_fsaverage(overlay, method='nearest', fsavg_density='10k')
p.add_layer({'left': outline_lh, 'right': outline_rh},
cmap='red_transparent', as_outline=True, cbar=False)
if legend == True:
kws = dict(location='bottom', draw_border=True, aspect=15, shrink=.2,
decimals=0, pad=-0.08)
fig = p.build(cbar_kws=kws)
else:
fig = p.build()
fig.axes[0].set_title(title, pad=-3)
#fig.show()