plotting¶
BrainData plotting functions.
Attributes:
| Name | Type | Description |
|---|---|---|
DEFAULT_SLICE_CUT_COORDS |
Methods:
| Name | Description |
|---|---|
auto_select_colormap | Auto-select colormap based on data characteristics. |
plot_brain | Plot BrainData instance using nilearn visualization or matplotlib. |
plot_flatmap_brain | Plot brain data on cortical flatmap. |
prepare_save_paths | Prepare save paths for multiple plot outputs. |
Methods¶
auto_select_colormap¶
auto_select_colormap(data)Auto-select colormap based on data characteristics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | ndarray | numpy array of brain data | required |
Returns:
| Name | Type | Description |
|---|---|---|
str | Colormap name |
plot_brain¶
plot_brain(bd, *, method = 'glass', upper = None, lower = None, threshold = None, view = 'z', cut_coords = None, cmap = None, bg_img = None, ax = None, figsize = (8, 6), title = None, colorbar = True, save = None, stat = 'mean', limit = 3, **kwargs)Plot BrainData instance using nilearn visualization or matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bd | BrainData instance. | required | |
method | str | Visualization type (‘glass’, ‘slices’, ‘timeseries’, ‘histogram’). | ‘glass’ |
upper | str / float | Upper threshold applied to the data (nltools semantics; may be a percentile string like "95%"). | None |
lower | str / float | Lower threshold applied to the data (nltools semantics). | None |
threshold | float | Absolute-value transparency cutoff forwarded to the underlying nilearn plot function. Voxels with `` | value |
view | str | For method="slices", any non-empty combination of "x", "y", "z" (e.g. "xyz", "xz", "y"). Default: "z". | ‘z’ |
cut_coords | list or dict | Cut coordinates for multi-slice views. If provided, takes precedence over view-based defaults. Either a list of per-axis coordinate sequences whose length matches view, or a dict keyed by axis letter ({"x": [...], "z": [...]}) from which entries for each axis in view are looked up. | None |
cmap | str | Colormap name. | None |
bg_img | Nifti1Image or str | Background image for slice views. | None |
ax | Axes | Matplotlib axis to plot on. | None |
figsize | tuple | default figure size if no axis (8, 6) | (8, 6) |
title | str | Plot title. | None |
colorbar | bool | Whether to show colorbar. Default: True. | True |
save | str | Path to save figure(s). | None |
stat | str | Statistic for timeseries plots. Valid options: ‘mean’, ‘median’, ‘std’. | ‘mean’ |
limit | int | Maximum number of images to render when bd contains multiple maps and method is "glass" or "slices". Default: 3. A warning is emitted if the data has more images than limit. Ignored for single-image data and for matplotlib-based methods ("timeseries", "histogram"), which already aggregate across images. | 3 |
**kwargs | Additional arguments passed to nilearn plot functions. | {} |
Returns:
| Type | Description |
|---|---|
| matplotlib.figure.Figure or list[matplotlib.figure.Figure]: For | |
| single-image data, the figure object (last one created if | |
method="slices" produced multiple per-axis figures). For | |
multi-image data with method in {"glass", "slices"}, a list | |
| of figures (one per image for glass; one per image-and-view pair for | |
| slices). All figures auto-display in notebooks. |
plot_flatmap_brain¶
plot_flatmap_brain(bd, *, threshold = None, cmap = 'RdBu_r', vmax = None, vmin = None, template = 'fsaverage5', with_curvature = True, curvature_contrast = 0.5, curvature_brightness = 0.5, transparency = 'auto', colorbar = True, colorbar_orientation = 'horizontal', figsize = (12, 6), title = None, radius_mm = 3.0, interpolation = 'linear', axes = None, save = None)Plot brain data on cortical flatmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bd | BrainData instance. | required | |
threshold | float | Values below this absolute threshold are masked. | None |
cmap | str | Matplotlib colormap for data. Default: ‘RdBu_r’. | ‘RdBu_r’ |
vmax | float | Maximum value for colormap. | None |
vmin | float | Minimum value for colormap. | None |
template | str | fsaverage resolution. Default: ‘fsaverage5’. | ‘fsaverage5’ |
with_curvature | bool | Show sulcal/gyral pattern. Default: True. | True |
curvature_contrast | float | Contrast of curvature. Default: 0.5. | 0.5 |
curvature_brightness | float | Mean brightness of curvature. Default: 0.5. | 0.5 |
transparency | str or float or array - like | Transparency/alpha applied to the surface data. 'auto' (default) lets the renderer choose. | ‘auto’ |
colorbar | bool | Show colorbar. Default: True. | True |
colorbar_orientation | str | ‘horizontal’ or ‘vertical’. Default: ‘horizontal’. | ‘horizontal’ |
figsize | tuple | Figure size. Default: (12, 6). | (12, 6) |
title | str | Figure title. | None |
radius_mm | float | sampling radius in mm for vol_to_surf. Default: 3.0. | 3.0 |
interpolation | str | Interpolation for vol_to_surf. Default: ‘linear’. | ‘linear’ |
axes | Axes | Existing axes to plot on. | None |
save | str | File path to save figure. | None |
Returns:
| Type | Description |
|---|---|
| matplotlib.figure.Figure |
prepare_save_paths¶
prepare_save_paths(save, idx = None)Prepare save paths for multiple plot outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save | Base save path (str or Path) | required | |
idx | int | Image index appended as _img{idx} to the base filename. Used to disambiguate saves across multiple images. | None |
Returns:
| Name | Type | Description |
|---|---|---|
dict | Dictionary with ‘glass’ and ‘slices’ keys containing save paths |