spectralbrain.viz.panels#

Parcellation-vs-clustering comparison panels in 3D.

The headline figure: a grid where each column is an anatomical view and each row is a distinct labeling — a reference parcellation (e.g. Schaefer-200, Brainnetome, an aseg structure) on the top row, and one or more data-driven clusterings (ddCRP, Leiden, consensus, …) on the rows below — every cell a 3D surface render coloured by that labeling. Works uniformly for hippocampi, whole brains, and white-matter bundle surfaces, because it operates on a generic (vertices, faces) mesh plus a dict of per-vertex labelings.

Rendering reuses SpectralBrain’s existing offscreen vedo pipeline (with a PyVista fallback); cells are composited into a single publication figure with row labels, view headers, and panel letters.

Functions

plot_parcellation_cluster_grid(vertices, ...)

3D grid comparing parcellations and clusterings side by side.

plot_parcellation_vs_clusters(vertices, ...)

Convenience wrapper: reference parcellation on top, clusterings below.

spectralbrain.viz.panels.plot_parcellation_cluster_grid(vertices, faces, labelings, *, views=None, engine='vedo', continuous=None, noise_color='lightgray', bg='white', cell_size=(600, 600), scale=2, panel_letters=True, title=None, save=None, dpi=300)[source]#

3D grid comparing parcellations and clusterings side by side.

Rows are the entries of labelings (insertion order: put the reference parcellation first, then each clustering); columns are anatomical views. Every cell is a 3D surface render coloured by that row’s labeling, from that column’s camera. Suitable for hippocampi, brains, and bundle surfaces.

Parameters:
  • vertices ((V, 3) array)

  • faces ((F, 3) array)

  • labelings (ordered mapping {name -> (V,) labels}) – e.g. {"Schaefer-200": atlas, "ddCRP": r1.labels, "Leiden": r2.labels}. Categorical by default; -1 is rendered as noise_color.

  • views (sequence of str, optional) – Camera presets (columns). Defaults to ["left_lateral", "anterior", "superior"]. Valid names: see spectralbrain.viz.clusters.CAMERA_PRESETS.

  • engine ({"vedo", "pyvista"}) – 3D rendering backend.

  • continuous (sequence of str, optional) – Names of labelings to render as continuous scalar maps (viridis) rather than categorical colours (e.g. a thickness/HKS overlay row).

  • cell_size ((w, h)) – Per-cell render size in pixels (before scale).

  • save (path-like, optional) – Output figure path (PNG/PDF). A sibling .png is also written for non-PNG outputs.

  • noise_color (str)

  • bg (str)

  • scale (int)

  • panel_letters (bool)

  • title (str | None)

  • dpi (int)

Returns:

(matplotlib.figure.Figure, dict) – The composited figure and metadata (rendered cell paths, grid shape).

spectralbrain.viz.panels.plot_parcellation_vs_clusters(vertices, faces, parcellation, clusterings, *, parcellation_name='Parcellation', **kwargs)[source]#

Convenience wrapper: reference parcellation on top, clusterings below.

clusterings may map names to label arrays or to ClusterResult objects (their .labels are used).

Parameters: