Hi everyone,
I have a 3D nifty file (brain map) that I would like to plot on a surface.
I am using the following code however, texture variable contains NaNs and the plotting function fails.
Any tip how to overcome this?
Code:
import numpy as np, os, sys
from nilearn import plotting, datasets; from nilearn.surface import load_surf_data
import numpy as np, os, warnings, matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
from matplotlib import ticker
from mpl_toolkits.mplot3d import Axes3D
from nilearn import surface
hemisphere = 'left'
view = 'medial'
black_bg = True
colorbar= True
cmap = 'hsv'
# Load the surface
fsaverage = datasets.fetch_surf_fsaverage('fsaverage')
# The stat map
stat_img = '/Users/loukas/Desktop/stat_map.nii'
# The texture
texture = surface.vol_to_surf(stat_img, fsaverage.pial_left)
fig = plt.figure(dpi=300)
ax = fig.add_subplot(111, projection='3d')
plt.gcf().axes[0].yaxis.set_major_formatter(ticker.FormatStrFormatter("%f"))
# Plotting
plotting.plot_surf_roi(fsaverage["infl_{}".format(hemisphere)], roi_map = texture, \
hemi = hemisphere, view = view, bg_map = fsaverage["sulc_{}".format(hemisphere)], \
bg_on_data = True, darkness = 0.6, output_file = 'mapped_signal.png', \
cmap = cmap, colorbar = colorbar, black_bg=black_bg, axes= ax, figure=fig, )
#for ax in plt.gcf().axes:
# ax.yaxis.set_major_formatter(ticker.FormatStrFormatter(">%.4f<"))
plotting.show()
plt.close()
Data: Easyupload.io - Upload files for free and transfer big files easily.
Pass: makis