Skip to main content

yet another brain plot

Project description

yabplot: yet another brain plot

logo

PyPI version Docs Tests DOI

yabplot is a Python library for creating beautiful, publication-quality 3D brain visualizations. it supports plotting cortical regions (+ vertexwise), subcortical structures, and white matter bundles.

the idea is simple. while there are already amazing visualization tools available, they often focus on specific domains—using one tool for white matter tracts and another for cortical surfaces inevitably leads to inconsistent styles. i wanted a unified, simple-to-use tool that enables me (and hopefully others) to perform most brain visualizations in a single place. recognizing that neuroscience evolves daily, i designed yabplot to be modular: it supports standard pre-packaged atlases out of the box, but easily accepts any custom parcellation or tractography dataset you might need.

features

  • pre-existing atlases: access many commonly used atlases (schaefer2018, brainnetome, aparc, aseg, musus100, xtract, etc) on demand.
  • [new!] vertexwise plotting: project volume (.nii) to cortical surface and plot.
  • simple to use: plug-n-play functions for cortex, subcortex, and tracts with a unified API.
  • custom atlases: easily use your own parcellations, segmentations (.nii/.gii), or tractograms (.trk).
  • flexible inputs: accepts data as dictionaries (for partial mapping) or arrays (for strict mapping).

installation

uv add yabplot # to install
uv sync --upgrade-package yabplot # to update

or

pip install yabplot # to install
pip install yabplot --upgrade # to update

dependencies: python 3.11 with ipywidgets, nibabel, pandas, pooch, pyvista, scikit-image, trame, trame-vtk, trame-vuetify

(Connectome Workbench (wb_command) is a requirement to create custom cortical atlases unless you plan to only use pre-loaded atlases; see more in docs)

quick start

please refer to the documentation for more comprehensive guides.

import yabplot as yab
import numpy as np

# check that you have the latest version
print(yab.__version__)

# see available atlases and brain meshes
print(yab.get_available_resources())

# see the region names for a specific atlas
print(yab.get_atlas_regions(atlas='aseg', category='subcortical'))

# cortical surfaces
atlas = 'aparc'
dmap1 = {'L_lateraloccipital': 0.265, 'L_postcentral': 0.086, ...}
dmap2 = {'L_fusiform': 0.218, 'L_supramarginal': 0.119, ...}
yab.plot_cortical(data=dmap1, atlas=atlas, vminmax=[-0.1, 0.3], 
                  bmesh_type='midthickness', views=['left_lateral', 'left_medial'],
                  figsize=(600, 300), cmap='viridis', proc_vertices='sharp')
yab.plot_cortical(data=dmap2, atlas=atlas, vminmax=[-0.1, 0.3], 
                  bmesh_type='swm', views=['left_lateral', 'left_medial'],
                  figsize=(1200, 600), cmap='viridis', proc_vertices='sharp')

# subcortical structures
atlas = 'aseg'
regs = yab.get_atlas_regions(atlas=atlas, category='subcortical')
data = np.arange(1, len(regs)+1)
yab.plot_subcortical(data=data, atlas=atlas, vminmax=[2, 14], 
                     views=['left_lateral', 'superior', 'right_lateral'], 
                     bmesh_alpha=0.1, figsize=(600, 300), cmap='viridis')

# white matter bundles
atlas = 'xtract_tiny'
regs = yab.get_atlas_regions(atlas=atlas, category='tracts')
data = {reg: np.sin(i) for i, reg in enumerate(regs)}
yab.plot_tracts(data=data, atlas=atlas, style='matte',
                views=['left_lateral', 'anterior', 'superior'], bmesh_type='pial',
                bmesh_alpha=0.1, figsize=(1600, 800), cmap='viridis')

examples

acknowledgements

yabplot relies on the extensive work of the neuroimaging community. if you use these atlases in your work, please cite the original authors. if you use this package for any scientific work, please cite the DOI (see more info on Zenodo).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yabplot-0.3.1.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yabplot-0.3.1-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file yabplot-0.3.1.tar.gz.

File metadata

  • Download URL: yabplot-0.3.1.tar.gz
  • Upload date:
  • Size: 30.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yabplot-0.3.1.tar.gz
Algorithm Hash digest
SHA256 002cab3c72e24e8be6c5a6c457c561ae107a4d1fcf56c94411b916c116761c3a
MD5 f983a107887c19bb15b351b82e52bf63
BLAKE2b-256 7272499b6acd201f023a71eb8dd2b19222053acc921d95ab8963cd5180d5e35f

See more details on using hashes here.

Provenance

The following attestation bundles were made for yabplot-0.3.1.tar.gz:

Publisher: publish.yml on teanijarv/yabplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yabplot-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: yabplot-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yabplot-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e8e9167325dbcca227dde2489bbf1575ccd02b2353e5f4a82b8a7ed28382924
MD5 c706e63d2fdb65e23c1fb94b93d54387
BLAKE2b-256 01db6563073808940979b2371108295c20e44be6f1fdde767c9e5142d318df36

See more details on using hashes here.

Provenance

The following attestation bundles were made for yabplot-0.3.1-py3-none-any.whl:

Publisher: publish.yml on teanijarv/yabplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page