Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

plotting

plotting

BrainData plotting functions.

Attributes:

NameTypeDescription
DEFAULT_SLICE_CUT_COORDS

Methods:

NameDescription
auto_select_colormapAuto-select colormap based on data characteristics.
plot_brainPlot BrainData instance using nilearn visualization or matplotlib.
plot_flatmap_brainPlot brain data on cortical flatmap.
prepare_save_pathsPrepare save paths for multiple plot outputs.

Methods

auto_select_colormap

auto_select_colormap(data)

Auto-select colormap based on data characteristics.

Parameters:

NameTypeDescriptionDefault
datandarraynumpy array of brain datarequired

Returns:

NameTypeDescription
strColormap 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:

NameTypeDescriptionDefault
bdBrainData instance.required
methodstrVisualization type (‘glass’, ‘slices’, ‘timeseries’, ‘histogram’).‘glass’
upperstr / floatUpper threshold applied to the data (nltools semantics; may be a percentile string like "95%").None
lowerstr / floatLower threshold applied to the data (nltools semantics).None
thresholdfloatAbsolute-value transparency cutoff forwarded to the underlying nilearn plot function. Voxels with ``value
viewstrFor method="slices", any non-empty combination of "x", "y", "z" (e.g. "xyz", "xz", "y"). Default: "z".‘z’
cut_coordslist or dictCut 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
cmapstrColormap name.None
bg_imgNifti1Image or strBackground image for slice views.None
axAxesMatplotlib axis to plot on.None
figsizetupledefault figure size if no axis (8, 6)(8, 6)
titlestrPlot title.None
colorbarboolWhether to show colorbar. Default: True.True
savestrPath to save figure(s).None
statstrStatistic for timeseries plots. Valid options: ‘mean’, ‘median’, ‘std’.‘mean’
limitintMaximum 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
**kwargsAdditional arguments passed to nilearn plot functions.{}

Returns:

TypeDescription
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:

NameTypeDescriptionDefault
bdBrainData instance.required
thresholdfloatValues below this absolute threshold are masked.None
cmapstrMatplotlib colormap for data. Default: ‘RdBu_r’.‘RdBu_r’
vmaxfloatMaximum value for colormap.None
vminfloatMinimum value for colormap.None
templatestrfsaverage resolution. Default: ‘fsaverage5’.‘fsaverage5’
with_curvatureboolShow sulcal/gyral pattern. Default: True.True
curvature_contrastfloatContrast of curvature. Default: 0.5.0.5
curvature_brightnessfloatMean brightness of curvature. Default: 0.5.0.5
transparencystr or float or array - likeTransparency/alpha applied to the surface data. 'auto' (default) lets the renderer choose.‘auto’
colorbarboolShow colorbar. Default: True.True
colorbar_orientationstr‘horizontal’ or ‘vertical’. Default: ‘horizontal’.‘horizontal’
figsizetupleFigure size. Default: (12, 6).(12, 6)
titlestrFigure title.None
radius_mmfloatsampling radius in mm for vol_to_surf. Default: 3.0.3.0
interpolationstrInterpolation for vol_to_surf. Default: ‘linear’.‘linear’
axesAxesExisting axes to plot on.None
savestrFile path to save figure.None

Returns:

TypeDescription
matplotlib.figure.Figure

prepare_save_paths

prepare_save_paths(save, idx = None)

Prepare save paths for multiple plot outputs.

Parameters:

NameTypeDescriptionDefault
saveBase save path (str or Path)required
idxintImage index appended as _img{idx} to the base filename. Used to disambiguate saves across multiple images.None

Returns:

NameTypeDescription
dictDictionary with ‘glass’ and ‘slices’ keys containing save paths