spectralbrain.viz.brainplots#
Publication-quality brain surface visualisations for spectral morphometry.
Architecture#
yabplot (PyVista/VTK) renders 3D brain surfaces to high-resolution
PNGs. matplotlib composites these PNGs into multi-row panels
styled by scienceplots (science + no-latex).
Every public function:
- Accepts nan_color, style, and display_type arguments.
- Returns (fig, axes) for further customisation.
- Accepts save= for automatic multi-format export (always PNG @600 dpi).
Figure types#
Single metric brain plot (cortical or subcortical)
Group comparison panel (A vs B vs A−B)
Normative deviation map (z-scores)
Atlas-free clustering map
Morphometric descriptor gallery (4–10 descriptors stacked)
Multi-descriptor comparison panel
Bilateral (L vs R) comparison
Spectral progression (HKS across t / WKS across e)
Tract visualisation
Subcortical structure panel
Module Attributes
Standard 6-view cortical row. |
|
7-view cortical + subcortical row. |
|
Classic 4-view medial/lateral row. |
Functions
|
Side-by-side L vs R hemisphere comparison (2 rows). |
|
Single-row brain surface plot. |
|
Single-row subcortical structure plot. |
|
White matter tract visualisation. |
|
Visualise atlas-free clustering on brain surface. |
|
Two- or three-row group comparison panel. |
|
Multi-row panel with one descriptor per row. |
|
Generic multi-row panel — the workhorse compositor. |
|
Normative z-score map with optional thresholded view. |
|
Multi-scale spectral descriptor progression. |
|
Pre-configured 10-row gallery for the canonical descriptors. |
Classes
|
Visual specification for one brain plot row. |
- class spectralbrain.viz.brainplots.BrainPlotSpec(label='', data=None, cmap='coolwarm', vminmax=<factory>, nan_color=(1.0, 1.0, 1.0), plot_kind='cortical', atlas=None, extra_kwargs=<factory>)[source]#
Bases:
objectVisual specification for one brain plot row.
Keeps colour range, cmap, and labels consistent across panels.
- Parameters:
label (str) – Row label (left margin annotation).
data (dict or ndarray or None) – Data for yabplot (parcellated dict or vertex-wise mesh).
cmap (str) – Matplotlib colourmap name.
vminmax (list) – [vmin, vmax]; [None, None] = auto from data.
nan_color (tuple or str) – Colour for NaN / medial wall / missing regions.
plot_kind (str) –
"cortical","subcortical","tracts","vertexwise".atlas (str or None) – Atlas name for parcellated data.
extra_kwargs (dict) – Additional kwargs passed to the yabplot function.
- spectralbrain.viz.brainplots.plot_bilateral_comparison(left_spec, right_spec, *, style='matte', display_type='none', title='L vs R Comparison', save=None, formats=None)[source]#
Side-by-side L vs R hemisphere comparison (2 rows).
- spectralbrain.viz.brainplots.plot_brain(data=None, *, atlas=None, plot_kind='cortical', cmap='coolwarm', vminmax=None, nan_color=(1.0, 1.0, 1.0), style='matte', display_type='none', views=None, title='', save=None, formats=None, **kwargs)[source]#
Single-row brain surface plot.
The basic building block — renders one metric across 6–7 views.
- Parameters:
data (dict or (lh_mesh, rh_mesh) or None) – Parcellated dict for cortical/subcortical, or (lh, rh) pyvista.PolyData tuple for vertex-wise.
atlas (str, optional)
plot_kind (str) –
"cortical","subcortical","tracts","vertexwise".cmap (str)
vminmax ([vmin, vmax] or None)
style (str) – yabplot lighting (
"matte","glossy","sculpted","flat").display_type (str) –
"none"for batch,"static"for notebooks.views (list of str, optional) – Default: 6-view cortical row.
title (str)
save (PathLike, optional)
kwargs (Any)
- Returns:
fig, ax
- Return type:
Examples
>>> plot_brain(z_scores, atlas='schaefer_200', cmap='RdBu_r', ... vminmax=[-3, 3], save='cortical_z.png')
- spectralbrain.viz.brainplots.plot_brain_subcortical(data=None, *, atlas='aseg', cmap='RdBu_r', vminmax=None, nan_color='#cccccc', nan_alpha=0.3, style='sculpted', bmesh_alpha=0.08, views=None, title='', save=None, display_type='none', **kwargs)[source]#
Single-row subcortical structure plot.
- spectralbrain.viz.brainplots.plot_brain_tracts(data=None, *, atlas='xtract_tiny', cmap='inferno', vminmax=None, nan_color='#BDBDBD', orientation_coloring=False, style='matte', display_type='none', views=None, title='', save=None, **kwargs)[source]#
White matter tract visualisation.
- Parameters:
- Return type:
- spectralbrain.viz.brainplots.plot_clustering_map(cluster_data, *, atlas=None, plot_kind='cortical', cmap='tab10', nan_color=(0.9, 0.9, 0.9), style='matte', display_type='none', views=None, title='Atlas-Free Clustering', save=None, **kwargs)[source]#
Visualise atlas-free clustering on brain surface.
- spectralbrain.viz.brainplots.plot_group_comparison(group_a, group_b, difference=None, *, views=None, style='matte', display_type='none', title='Group Comparison', save=None, formats=None)[source]#
Two- or three-row group comparison panel.
- Parameters:
group_a (BrainPlotSpec) – Control group (typically blue-ish cmap).
group_b (BrainPlotSpec) – Patient group.
difference (BrainPlotSpec, optional) – A − B difference map (diverging cmap, symmetric vminmax).
style (str)
display_type (str)
title (str)
save (PathLike, optional)
- Returns:
fig, axes
- Return type:
- spectralbrain.viz.brainplots.plot_morphometric_gallery(specs, *, views=None, style='matte', display_type='none', title='Spectral Morphometry Gallery', panel_width_in=12.0, row_height_in=1.4, save=None, formats=None)[source]#
Multi-row panel with one descriptor per row.
The flagship figure for spectral morphometry papers — stack 4–10 descriptors with consistent views for visual comparison.
- Parameters:
- Returns:
fig, axes
- Return type:
Examples
>>> specs = [ ... BrainPlotSpec.from_descriptor("hks", data=hks_dict), ... BrainPlotSpec.from_descriptor("wks", data=wks_dict), ... BrainPlotSpec.from_descriptor("bks", data=bks_dict), ... BrainPlotSpec.from_descriptor("shape_idx", data=si_dict), ... BrainPlotSpec.from_descriptor("casorati", data=cas_dict), ... ] >>> fig, axes = plot_morphometric_gallery(specs, save='gallery.png')
- spectralbrain.viz.brainplots.plot_multi_descriptor_panel(rows, *, views=None, style='matte', display_type='none', title='', panel_width_in=12.0, row_height_in=1.5, save=None, formats=None)[source]#
Generic multi-row panel — the workhorse compositor.
- spectralbrain.viz.brainplots.plot_normative_map(z_data, *, atlas=None, plot_kind='cortical', threshold=2.0, cmap='coolwarm', vminmax=None, nan_color=(0.85, 0.85, 0.85), style='matte', display_type='none', views=None, title='Normative Deviation', show_thresholded=True, save=None, formats=None)[source]#
Normative z-score map with optional thresholded view.
- Parameters:
- Returns:
fig, axes
- Return type:
- spectralbrain.viz.brainplots.plot_spectral_progression(scale_specs, *, descriptor_name='HKS', views=None, style='matte', display_type='none', title=None, save=None, formats=None)[source]#
Multi-scale spectral descriptor progression.
One row per scale parameter (time for HKS, energy for WKS). Visually demonstrates how the descriptor captures geometry at different spatial frequencies.
- Parameters:
- Return type:
- spectralbrain.viz.brainplots.plot_top10_morphometrics(descriptor_data, *, atlas=None, plot_kind='cortical', views=None, style='matte', display_type='none', title='Top 10 Spectral Morphometrics', save=None, formats=None)[source]#
Pre-configured 10-row gallery for the canonical descriptors.
- spectralbrain.viz.brainplots.VIEWS_CORTEX: list[str] = ['right_lateral', 'anterior', 'left_lateral', 'posterior', 'superior', 'inferior']#
Standard 6-view cortical row.