-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplot.py
More file actions
111 lines (105 loc) · 4.43 KB
/
plot.py
File metadata and controls
111 lines (105 loc) · 4.43 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import numpy as np
import os
import sys
import nibabel as nb
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from matplotlib.colors import ListedColormap
import SUITPy as suit
import warnings
_base_dir = os.path.dirname(os.path.abspath(__file__))
_surf_dir = os.path.join(_base_dir, 'standard_mesh')
def plotmap(
data,
surf=None,
underlay=None,
undermap='gray',
underscale=[-1.5, 1],
overlay_type='func',
threshold=None,
cmap=None,
cscale=None,
label_names=None,
borders=None,
bordercolor = 'k',
bordersize = 2,
alpha=1.0,
render='matplotlib',
hover = 'auto',
new_figure=False,
colorbar=False,
cbar_tick_format="%.2g",
backgroundcolor = 'w',
frame = None
):
"""Plot activity on a flatmap
Args:
data (np.array, giftiImage, or name of gifti file):
Data to be plotted, should be a 28935x1 vector
surf (str or giftiImage):
surface file for flatmap, or ('fs32k_L','fs32k_R')
underlay (str, giftiImage, or np-array):
Full filepath of the file determining underlay coloring (default: sulc for standard surface)
undermap (str)
Matplotlib colormap used for underlay (default: gray)
underscale (array-like)
Colorscale [min, max] for the underlay (default: [-1, 0.5])
overlay_type (str)
'func': functional activation (default)
'label': categories
'rgb': RGB(A) values (0-1) directly specified. Alpha is optional
threshold (scalar or array-like)
Threshold for functional overlay. If one value is given, it is used as a positive threshold.
If two values are given, an positive and negative threshold is used.
cmap (str)
A Matplotlib colormap or an equivalent Nx3 or Nx4 floating point array (N rgb or rgba values). (defaults to 'jet' if none given)
label_names (list)
labelnames (default is None - extracts from .label.gii )
borders (str)
Full filepath of the borders txt file
bordercolor (char or matplotlib.color)
Color of border - defaults to 'k'
bordersize (int)
Size of the border points - defaults to 2
cscale (int array)
Colorscale [min, max] for the overlay, valid input values from -1 to 1 (default: [overlay.max, overlay.min])
alpha (float)
Opacity of the overlay (default: 1)
render (str)
Renderer for graphic display 'matplot' / 'plotly'. Dafault is matplotlib
hover (str)
When renderer is plotly, it determines what is displayed in the hover label: 'auto', 'value', or None
new_figure (bool)
If False, plot renders into matplotlib's current axis. If True, it creates a new figure (default=True)
colorbar (bool)
By default, colorbar is not plotted into matplotlib's current axis (or new figure if new_figure is set to True)
cbar_tick_format : str, optional
Controls how to format the tick labels of the colorbar, and for the hover label.
Ex: use "%i" to display as integers.
Default='%.2g' for scientific notation.
backgroundcolor (str):
Color for the background of the plot (default: 'w')
frame (list): [Left, Right, Top, Bottom] margins for the plot (default: plot entire surface )
Returns:
ax (matplotlib.axis)
If render is matplotlib, the function returns the axis
fig (plotly.go.Figure)
If render is plotly, it returns Figure object
"""
if surf=='fs32k_L':
surf = os.path.join(_surf_dir,'fs_L','fs_LR.32k.L.flat.surf.gii')
if underlay is None:
underlay = os.path.join(_surf_dir,'fs_L','fs_LR.32k.L.shape.gii')
elif surf=='fs32k_R':
surf = os.path.join(_surf_dir,'fs_R','fs_LR.32k.R.flat.surf.gii')
if underlay is None:
underlay = os.path.join(_surf_dir,'fs_R','fs_LR.32k.R.shape.gii')
fig = suit.flatmap.plot( data,surf,
underlay,undermap,underscale,
overlay_type,threshold,cmap,cscale,label_names,
borders,bordercolor,bordersize,
alpha,render,hover,new_figure,colorbar,
cbar_tick_format,backgroundcolor,frame)
return fig