Visualization¶
The viz module provides plotting utilities for displaying source estimates and comparing inverse solutions.
Overview¶
Visualization options include:
- Glass brain plots: 2D projections showing source activity overlaid on a transparent brain
- 3D glass brain: Interactive 3D visualization of source estimates
- Surface plots: Activity mapped onto the cortical surface
Quick Start¶
from invert.viz import plot_glass_brain, plot_surface
# Plot source estimate on glass brain
fig = plot_glass_brain(stc, forward)
# Plot on cortical surface
fig = plot_surface(stc, subject='fsaverage', subjects_dir=subjects_dir)
API Reference¶
Glass Brain Plots¶
invert.viz.plot_glass_brain ¶
plot_glass_brain(
stc,
src,
time_idx=None,
threshold=0.2,
cmap="magma",
alpha=0.8,
marker_size=15,
brain_alpha=0.1,
brain_color="0.7",
figsize=(12, 4),
title=None,
ax=None,
)
Plot a glass-brain projection of a SourceEstimate.
Shows a faint outline of all source positions (the brain shape) with supra-threshold activations overlaid in colour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stc
|
SourceEstimate
|
Source estimate returned by a solver. |
required |
src
|
SourceSpaces
|
Source space, typically |
required |
time_idx
|
int | None
|
Time sample index to plot. If None, plots the time point with maximum activation. If the data is a single time point, uses that. |
None
|
threshold
|
float
|
Fraction of the peak value below which sources are hidden. 0.0 shows all sources, 0.5 hides the bottom 50 %. |
0.2
|
cmap
|
str
|
Matplotlib colormap name. |
'magma'
|
alpha
|
float
|
Marker transparency for active sources. |
0.8
|
marker_size
|
float
|
Scatter marker size for active sources. |
15
|
brain_alpha
|
float
|
Transparency for the brain outline. |
0.1
|
brain_color
|
str
|
Color for the brain outline. |
'0.7'
|
figsize
|
tuple
|
Figure size (width, height) in inches. |
(12, 4)
|
title
|
str | None
|
Figure title. |
None
|
ax
|
array of Axes | None
|
Three matplotlib Axes to draw into. If None, a new figure is created. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
The figure. |
Source code in invert/viz/glass_brain.py
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
3D Glass Brain¶
invert.viz.plot_3d_glass_brain ¶
plot_3d_glass_brain(
stc,
src,
time_idx=None,
threshold=0.2,
cmap="magma",
alpha=0.9,
marker_size=30,
brain_alpha=0.05,
brain_color="0.7",
figsize=(8, 8),
title=None,
ax=None,
view=(90, 10),
depth_scale=True,
)
Plot a 3D-like glass brain visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stc
|
SourceEstimate
|
Source estimate. |
required |
src
|
SourceSpaces
|
Source space. |
required |
time_idx
|
int | None
|
Time index to plot. |
None
|
threshold
|
float
|
Threshold fraction (0.0 to 1.0) of peak activation. |
0.2
|
cmap
|
str
|
Colormap. |
'magma'
|
alpha
|
float
|
Opacity of active sources. |
0.9
|
marker_size
|
float
|
Base marker size. |
30
|
brain_alpha
|
float
|
Opacity of the inactive source cloud. |
0.05
|
brain_color
|
str
|
Color of the brain outline/cloud. |
'0.7'
|
figsize
|
tuple
|
Figure size. |
(8, 8)
|
title
|
str | None
|
Title. |
None
|
ax
|
Axes | None
|
Axes to plot on. |
None
|
view
|
tuple
|
(azimuth, elevation) in degrees. |
(90, 10)
|
depth_scale
|
bool
|
Whether to scale marker size by depth. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
The figure. |
Source code in invert/viz/glass_brain_3d.py
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
Surface Plots¶
invert.viz.plot_surface ¶
plot_surface(
stc,
src,
time_idx=None,
threshold=0.2,
cmap="magma",
background="white",
views=None,
figsize=(1200, 400),
title=None,
screenshot_path=None,
show=True,
)
Plot source activations on the cortical surface mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stc
|
SourceEstimate
|
Source estimate returned by a solver. |
required |
src
|
SourceSpaces
|
Source space, typically |
required |
time_idx
|
int | None
|
Time sample index to plot. If None, uses the time of peak activation. |
None
|
threshold
|
float
|
Fraction of peak below which activations are hidden (transparent). |
0.2
|
cmap
|
str
|
Colormap for activations. |
'magma'
|
background
|
str
|
Background color of the rendering window. |
'white'
|
views
|
list of str | None
|
Camera views to show. Defaults to |
None
|
figsize
|
tuple
|
Window size (width, height) in pixels. |
(1200, 400)
|
title
|
str | None
|
Window title. |
None
|
screenshot_path
|
str | None
|
If provided, saves a screenshot to this path and returns the image array instead of showing the interactive window. |
None
|
show
|
bool
|
Whether to display the interactive window (ignored if screenshot_path is set). |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
plotter |
Plotter
|
The plotter instance. |
Source code in invert/viz/surface.py
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |