plotting API
yabplot.plotting.plot_cortical(data=None, atlas=None, custom_atlas_path=None, ax=None, cbar_kwargs=None, views=None, layout=None, bmesh='midthickness', figsize=None, cmap='coolwarm', vminmax=[None, None], nan_color=(1.0, 1.0, 1.0), style='default', zoom=1.2, proc_vertices='sharp', display_type='matplotlib', export_path=None, contours=False)
Visualize data on the cortical surface using a specified atlas.
This function maps scalar values to cortical regions (parcellations) on a standard surface mesh (Conte69). It supports both pre-existing atlases and custom local atlases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(dict, list, ndarray)
|
Data to map onto the cortex.
If dict: Keys must match region names in the atlas (see |
None
|
atlas
|
str
|
Name of the standard atlas to use (e.g., 'schaefer_100', see 'yabplot.get_available_resources' for more). Defaults to 'aparc' if neither atlas nor custom_atlas_path is provided. |
None
|
custom_atlas_path
|
str
|
Path to a local directory containing custom atlas files. The directory must
contain a CSV mapping regions to vertices and a LUT text file. If provided, |
None
|
views
|
list of str
|
Views to display. Can be a list of presets ('left_lateral', 'right_medial', etc.) or a dictionary of camera configurations. Defaults to all views. |
None
|
layout
|
tuple(rows, cols)
|
Grid layout for subplots. If None, automatically calculated based on the number of views. |
None
|
bmesh
|
str
|
Name of the background context brain mesh (e.g., 'midthickness', 'white', 'swm', etc). Default is 'midthickness'. |
'midthickness'
|
figsize
|
tuple(width, height)
|
Window size in inches. If None, automatically calculated based on the number of views and layout. |
None
|
cmap
|
str or Colormap
|
Colormap for continuous data. Ignored if |
'coolwarm'
|
vminmax
|
list[min, max]
|
Manual lower and upper bounds for the colormap. If [None, None], bounds are inferred from the data range. |
[None, None]
|
nan_color
|
tuple or str
|
Color for regions with missing (NaN) data or the medial wall. Default is white. |
(1.0, 1.0, 1.0)
|
style
|
str
|
Lighting preset ('default', 'matte', 'glossy', 'sculpted', 'flat'). |
'default'
|
zoom
|
float
|
Camera zoom level. >1.0 zooms in, <1.0 zooms out. Default is 1.2. |
1.2
|
proc_vertices
|
str or None
|
Whether to process the vertices edges according to geometry of bmesh. Set to None to not perform. 'blur': Applies simple blurring between different color vertices. 'sharp': Applies sharpening of the resolution of different color vertices (default). |
'sharp'
|
display_type
|
(matplotlib, interactive, pyvista, object)
|
'matplotlib': returns a matplotlib figure and axis (default). 'interactive': opens an interactive trame viewer in the browser. 'pyvista': returns a static jupyter widget (legacy behavior). 'object': returns the raw pyvista plotter object. |
'matplotlib'
|
export_path
|
str
|
If provided, saves the final figure to this path (e.g., 'figure.png'). |
None
|
contours
|
bool, dict, list, str, or numpy.ndarray
|
Draw boundary lines between atlas regions. Default
|
False
|
Returns:
| Type | Description |
|---|---|
Axes or Plotter or DisplayObject
|
returns based on display_type: - 'matplotlib': returns a matplotlib axes object. - 'interactive': returns a trame browser viewer. - 'pyvista': returns a static jupyter widget. - 'object': returns the raw pyvista plotter. |
Source code in yabplot/plotting.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
yabplot.plotting.plot_subcortical(data=None, atlas=None, custom_atlas_path=None, ax=None, cbar_kwargs=None, views=None, layout=None, figsize=None, cmap=None, vminmax=[None, None], nan_color='#cccccc', nan_alpha=1.0, style='default', bmesh='midthickness', bmesh_alpha=0.15, bmesh_color='lightgray', zoom=1.2, display_type='matplotlib', export_path=None, custom_atlas_proc=dict(smooth_i=15, smooth_f=0.6), atlas_color_seed=42, plot_regions_separately=False, shared_hemisphere_colors=False)
Visualize data on the subcortical structures using a specified atlas.
Renders volumetric structures as 3D meshes. Supports pre-existing atlases and on-the-fly conversion of GIfTI surfaces to smooth meshes for custom atlases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(dict, list, ndarray, Series, DataFrame)
|
Scalar values for each subcortical region. If dict/pd.Series/pd.DataFrame: Values according to region names. If array/list: Must strictly match the sorted order of regions in the atlas. |
None
|
atlas
|
str
|
Name of the standard atlas to use (e.g., 'musus_100', see 'yabplot.get_available_resources' for more). Defaults to 'aseg' if neither atlas nor custom_atlas_path is provided. |
None
|
custom_atlas_path
|
str
|
Path to a local directory containing .vtk or .gii mesh files for each region. |
None
|
views
|
list of str
|
Views to display. Can be a list of presets ('left_lateral', 'right_medial', etc.) or a dictionary of camera configurations. Defaults to all views. |
None
|
layout
|
tuple(rows, cols)
|
Grid layout for subplots. If None, automatically calculated based on the number of views. |
None
|
figsize
|
tuple(width, height)
|
Window size in inches. If None, automatically calculated based on the number of views and layout. |
None
|
cmap
|
str or Colormap
|
Colormap for continuous data. Defaults to 'coolwarm' when |
None
|
vminmax
|
list[min, max]
|
Manual lower and upper bounds for the colormap. If [None, None], bounds are inferred from the data range. |
[None, None]
|
nan_color
|
str or tuple
|
Color for regions with no data (NaN). Default is light grey '#cccccc'. |
'#cccccc'
|
nan_alpha
|
float
|
Opacity (0.0 to 1.0) for regions with no data. Set to 0.0 to hide them. |
1.0
|
style
|
str
|
Lighting preset ('default', 'matte', 'glossy', 'sculpted', 'flat'). |
'default'
|
bmesh
|
PolyData or dict
|
Configure background context brain mesh. Accepts a string (e.g., 'midthickness', 'white', 'swm', etc), single PolyData (used for both hemispheres) or a dict with 'L'/'R' keys. Default is 'midthickness'. |
'midthickness'
|
bmesh_alpha
|
float
|
Opacity of the context brain mesh. Default is 0.15. |
0.15
|
bmesh_color
|
str
|
Color of the context brain mesh. |
'lightgray'
|
zoom
|
float
|
Camera zoom level. >1.0 zooms in, <1.0 zooms out. Default is 1.2. |
1.2
|
display_type
|
(matplotlib, interactive, pyvista, object)
|
'matplotlib': returns a matplotlib figure and axis (default). 'interactive': opens an interactive trame viewer in the browser. 'pyvista': returns a static jupyter widget (legacy behavior). 'object': returns the raw pyvista plotter object. |
'matplotlib'
|
export_path
|
str
|
If provided, saves the final figure to this path (e.g., 'figure.png').
With |
None
|
custom_atlas_proc
|
dict
|
Parameters for processing custom GIfTI files. Keys: 'smooth_i' (iterations) and 'smooth_f' (relaxation factor). Default is {'smooth_i': 15, 'smooth_f': 0.6}. |
dict(smooth_i=15, smooth_f=0.6)
|
atlas_color_seed
|
int
|
Seed controlling the categorical color arrangement in atlas (no-data) mode.
With the default palette it seeds the distinct-color generator; with a
colormap it seeds a shuffle so gradient-adjacent regions get contrasting
colors. Change it to get a different, reproducible arrangement. Ignored when
|
42
|
plot_regions_separately
|
bool
|
If True, renders each region + view combination on its own instead of a single
combined figure. If |
False
|
shared_hemisphere_colors
|
bool
|
If True, bilateral region pairs (e.g. |
False
|
Returns:
| Type | Description |
|---|---|
Axes or Plotter or DisplayObject
|
returns based on display_type:
- 'matplotlib': returns a matplotlib axes object.
- 'interactive': returns a trame browser viewer.
- 'pyvista': returns a static jupyter widget.
- 'object': returns the raw pyvista plotter.
with |
Source code in yabplot/plotting.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 | |
yabplot.plotting.plot_tracts(data=None, atlas=None, custom_atlas_path=None, ax=None, cbar_kwargs=None, views=None, layout=None, figsize=None, cmap='coolwarm', alpha=1.0, vminmax=[None, None], nan_color='#BDBDBD', nan_alpha=1.0, style='default', bmesh='midthickness', bmesh_alpha=0.15, bmesh_color='lightgray', zoom=1.2, orientation_coloring=False, display_type='matplotlib', tract_kwargs=dict(render_lines_as_tubes=True, line_width=1.2), export_path=None)
Visualize data on the white matter tractography bundles using a specified atlas.
Renders streamlines from .trk files. Can color tracts by scalar values, categorically, or by local fiber orientation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(dict, list, ndarray, Series, DataFrame)
|
Scalar values for each tract, or mrtrix3 derived .tsf file path for each tract. If dict: Keys must match tract names. If array/list: Must strictly match the sorted list of tracts in the atlas. If None: Tracts are colored by category (distinct colors) or orientation. |
None
|
atlas
|
str
|
Name of the standard tract atlas (e.g., 'hcp1065_small', see 'yabplot.get_available_resources' for more). Defaults to 'xtract_tiny'. |
None
|
custom_atlas_path
|
str
|
Path to a local directory containing .trk files for each tract. |
None
|
views
|
list of str
|
Views to display. Can be a list of presets ('left_lateral', 'right_medial', etc.) or a dictionary of camera configurations. Defaults to all views. |
None
|
layout
|
tuple(rows, cols)
|
Grid layout for subplots. If None, automatically calculated based on the number of views. |
None
|
figsize
|
tuple(width, height)
|
Window size in inches. If None, automatically calculated based on the number of views and layout. |
None
|
cmap
|
str or Colormap
|
Colormap for continuous data. Ignored if |
'coolwarm'
|
alpha
|
float
|
Opacity of the tracts (0.0 to 1.0). |
1.0
|
vminmax
|
list[min, max]
|
Manual lower and upper bounds for the colormap. If [None, None], bounds are inferred from the data range. |
[None, None]
|
nan_color
|
str
|
Color for tracts with missing data (NaN). Default is grey '#BDBDBD'. |
'#BDBDBD'
|
nan_alpha
|
float
|
Opacity (0.0 to 1.0) for regions with no data. Set to 0.0 to hide them. |
1.0
|
style
|
str
|
Lighting preset ('default', 'matte', 'glossy', 'sculpted', 'flat'). |
'default'
|
bmesh
|
PolyData or dict
|
Configure background context brain mesh. Accepts a string (e.g., 'midthickness', 'white', 'swm', etc), single PolyData (used for both hemispheres) or a dict with 'L'/'R' keys. Default is 'midthickness'. |
'midthickness'
|
bmesh_alpha
|
float
|
Opacity of the context brain mesh. Default is 0.15. |
0.15
|
bmesh_color
|
str
|
Color of the context brain mesh. |
'lightgray'
|
zoom
|
float
|
Camera zoom level. >1.0 zooms in, <1.0 zooms out. Default is 1.2. |
1.2
|
orientation_coloring
|
bool
|
If True, ignores |
False
|
tract_kwargs
|
dict
|
Additional arguments passed to PyVista's |
dict(render_lines_as_tubes=True, line_width=1.2)
|
display_type
|
(matplotlib, interactive, pyvista, object)
|
'matplotlib': returns a matplotlib figure and axis (default). 'interactive': opens an interactive trame viewer in the browser. 'pyvista': returns a static jupyter widget (legacy behavior). 'object': returns the raw pyvista plotter object. |
'matplotlib'
|
export_path
|
str
|
If provided, saves the final figure to this path (e.g., 'figure.png'). |
None
|
Returns:
| Type | Description |
|---|---|
Axes or Plotter or DisplayObject
|
returns based on display_type: - 'matplotlib': returns a matplotlib axes object. - 'interactive': returns a trame browser viewer. - 'pyvista': returns a static jupyter widget. - 'object': returns the raw pyvista plotter. |
Source code in yabplot/plotting.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 | |
yabplot.plotting.plot_voxelwise(nii_path, threshold='95%', n_levels=20, ax=None, cbar_kwargs=None, views=None, layout=None, figsize=None, cmap='coolwarm', vminmax=[None, None], blur_sigma=0.0, smooth_i=0, smooth_f=0.0, style='default', bmesh='midthickness', bmesh_alpha=0.15, bmesh_color='lightgray', ignore_bmesh=True, zoom=1.2, display_type='matplotlib', export_path=None)
Visualize 3D voxelwise data from a NIfTI file by extracting it as surface meshes.
This function extracts topographical shells (isosurfaces) from a volumetric image and renders them within a transparent brain mesh and makes the high-intensity layers with higher priority and more visible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nii_path
|
str
|
Path to the NIfTI file to visualize. |
required |
threshold
|
float or str
|
Value below which voxels are hidden. Can be a float or a percentage string like '95%'. Default is '95%'. |
'95%'
|
n_levels
|
int
|
Number of nested isosurfaces to generate. Higher values show more detail of the internal intensity gradient. Default is 20. |
20
|
ax
|
Axes
|
Matplotlib axis to render into if display_type is 'matplotlib'. |
None
|
cbar_kwargs
|
dict
|
Arguments passed to the colorbar. |
None
|
views
|
list of str
|
Views to display (e.g. 'left_lateral', 'superior'). Defaults to all views. |
None
|
layout
|
tuple(rows, cols)
|
Grid layout for subplots. If None, auto-calculated. |
None
|
figsize
|
tuple(width, height)
|
Window size in inches. |
None
|
cmap
|
str or Colormap
|
Colormap for the continuous voxel data. |
'coolwarm'
|
vminmax
|
list[min, max]
|
Colormap bounds. If [None, None], uses robust 1st/99th percentiles. |
[None, None]
|
blur_sigma
|
float
|
Gaussian blur (voxel units) applied before thresholding for smoother geometry. |
0.0
|
smooth_i
|
int
|
Number of Laplacian smoothing iterations for the extracted mesh. |
0
|
smooth_f
|
float
|
Relaxation factor for mesh smoothing. |
0.0
|
style
|
str
|
Lighting preset ('default', 'matte', 'glossy', 'sculpted', 'flat'). |
'default'
|
bmesh
|
str, dict, or pyvista.PolyData
|
Background context brain mesh. Accepts the name of a built-in mesh
(e.g. 'midthickness', 'pial'; see |
'midthickness'
|
bmesh_alpha
|
float
|
Opacity of the context brain mesh. Default is 0.15. |
0.15
|
bmesh_color
|
str
|
Color of the context brain mesh. |
'lightgray'
|
ignore_bmesh
|
bool
|
If True (default), data renders on top of brain regardless of depth (X-ray). If False, brain surface correctly obscures the internal data. |
True
|
zoom
|
float
|
Camera zoom level. Default is 1.2. |
1.2
|
display_type
|
(matplotlib, interactive, pyvista, object)
|
Rendering backend and return type. Default is 'matplotlib'. |
'matplotlib'
|
export_path
|
str
|
If provided, saves the final figure to this path. |
None
|
Returns:
| Type | Description |
|---|---|
Axes or Plotter or DisplayObject
|
returns based on display_type: - 'matplotlib': returns a matplotlib axes object. - 'interactive': returns a trame browser viewer. - 'pyvista': returns a static jupyter widget. - 'object': returns the raw pyvista plotter object. |
Notes
The volume is placed using the affine stored in the NIfTI header. It is not resampled or registered, so it can be in any space, but it only lines up with the context brain if both are in the same space.
The built-in meshes are group-average cortical surfaces from the Human
Connectome Project (fs_LR 32k) in MNI152NLin6Asym space, without cerebellum
or brainstem. For data in another space (e.g. MNI152NLin2009cAsym from
fMRIPrep, or a subject's native space), build a matching context brain with
load_nii_as_mesh, for instance from a brain mask, and pass it as bmesh.
Source code in yabplot/plotting.py
1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 | |
yabplot.plotting.plot_vertexwise(lh, rh, scalars='Data', ax=None, cbar_kwargs=None, views=None, layout=None, figsize=None, cmap='coolwarm', vminmax=[None, None], nan_color=(1.0, 1.0, 1.0), style='default', zoom=1.2, display_type='matplotlib', export_path=None, lut=None, proc_vertices='sharp')
Visualize arbitrary per-vertex scalar data on a user-supplied brain mesh.
Unlike plot_cortical, this function requires no atlas. The user provides
PyVista PolyData meshes with per-vertex scalar data stored under the key specified
by scalars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lh
|
PolyData
|
Left hemisphere mesh containing a (N,) float array under |
required |
rh
|
PolyData
|
Right hemisphere mesh containing a (N,) float array under |
required |
scalars
|
str
|
The string key corresponding to the scalar data array in the PyVista point data dictionary. Default is 'Data'. |
'Data'
|
views
|
list of str
|
Can be a list of presets ('left_lateral', 'right_medial', etc.) or a dictionary of camera configurations. Defaults to all views. |
None
|
layout
|
tuple(rows, cols)
|
Grid layout for subplots. If None, auto-calculated. |
None
|
figsize
|
tuple(width, height)
|
Window size in inches. If None, automatically calculated based on the number of views and layout. |
None
|
cmap
|
str or Colormap
|
Colormap. Default is 'coolwarm'. |
'coolwarm'
|
vminmax
|
list[min, max]
|
Colormap bounds. If [None, None], inferred from data range. |
[None, None]
|
nan_color
|
tuple or str
|
Color for NaN vertices. Default is white. |
(1.0, 1.0, 1.0)
|
style
|
str
|
Lighting preset ('default', 'matte', 'glossy', 'sculpted', 'flat'). |
'default'
|
zoom
|
float
|
Camera zoom level. Default is 1.2. |
1.2
|
display_type
|
(matplotlib, interactive, pyvista, object)
|
'matplotlib': returns a matplotlib figure and axis (default). 'interactive': opens an interactive trame viewer in the browser. 'pyvista': returns a static jupyter widget (legacy behavior). 'object': returns the raw pyvista plotter object. |
'matplotlib'
|
export_path
|
str
|
If provided, saves the figure to this path. |
None
|
lut
|
(list, ndarray or auto)
|
Lookup table for categorical data (e.g., labels or clusters), where |
None
|
proc_vertices
|
str or None
|
Whether to process the vertices edges between labels. Only used when |
'sharp'
|
Returns:
| Type | Description |
|---|---|
Axes or Plotter or DisplayObject
|
returns based on display_type: - 'matplotlib': returns a matplotlib axes object. - 'interactive': returns a trame browser viewer. - 'pyvista': returns a static jupyter widget. - 'object': returns the raw pyvista plotter. |
See Also
yabplot.mesh.load_vertexwise_mesh
Examples:
>>> from yabplot.mesh import load_vertexwise_mesh
>>> lh, rh = load_vertexwise_mesh(
... fsaverage.pial_left, fsaverage.pial_right,
... d_values_lh, d_values_rh
... )
>>> # If your data was injected under the default 'Data' key
>>> plot_vertexwise(lh, rh, views=['left_lateral', 'right_lateral'])
>>>
>>> # If your data was injected under a custom key
>>> lh['thickness'] = lh_thick_array
>>> rh['thickness'] = rh_thick_array
>>> plot_vertexwise(lh, rh, scalars='thickness', cmap='inferno')
>>>
>>> # If your data are labels (e.g., clusters 1 and 2), color label i with lut[i]
>>> plot_vertexwise(lh, rh, scalars='clusters', lut=['white', 'red', 'blue'])
Source code in yabplot/plotting.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
yabplot.plotting.plot_connectome(matrix=None, atlas=None, custom_atlas_path=None, ax=None, cbar_kwargs=None, views=None, layout=None, figsize=None, node_color='strength', node_size='strength', node_cmap='binary', node_vminmax=[None, None], edge_threshold='95%', edge_thickness='weight', edge_scaling=1.0, edge_cmap='coolwarm', edge_color=None, edge_alpha=1.0, edge_vminmax=[None, None], edge_curve=0.1, directed=False, style='default', bmesh_type='midthickness', bmesh_alpha=0.15, bmesh_color='lightgray', zoom=1.2, display_type='matplotlib', export_path=None)
visualizes an n x n connectivity matrix as a 3d network in the brain.
calculates spatial centroids for atlas regions and renders connectivity weights as 3d tubes (edges) and spheres (nodes) within a transparent brain hull.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray or dataframe
|
the (n, n) connectivity matrix. if none, only nodes are plotted. nan values are handled gracefully. |
None
|
atlas
|
str
|
name of the atlas mapping the regions (e.g., 'aparc', 'aseg'). |
None
|
custom_atlas_path
|
str
|
path to custom atlas files if bypassing the built-in registry. |
None
|
views
|
list of str
|
list of views to render (e.g., ['left_lateral', 'superior']). |
None
|
layout
|
tuple
|
plotter grid layout (nrows, ncols). auto-generated if none. |
None
|
figsize
|
tuple
|
window size in inches (width, height). If None, automatically calculated based on layout. |
None
|
node_color
|
(str, array, dict)
|
can be 'atlas' (default categorical colors), 'strength' (graph metric), a static color string ('red'), or a custom data array/dict of matching length. default is 'strength' (when no matrix is provided, then 'atlas' is used). |
'strength'
|
node_size
|
(float, str, array, dict)
|
constant float radius, 'strength' (graph metric), or a custom data array/dict to scale node sizes. default is 'strength' (when no matrix is provided, then 'atlas' is used). |
'strength'
|
node_cmap
|
str
|
colormap name for mapped node colors. default is 'binary'. |
'binary'
|
node_vminmax
|
list
|
[vmin, vmax] for node colormap clipping. |
[None, None]
|
edge_threshold
|
float or str
|
minimum absolute weight to display an edge. strings like '90%' calculate percentiles of the matrix. default is '95%'. |
'95%'
|
edge_thickness
|
float or str
|
'weight' to scale by connection strength, or a constant float. |
'weight'
|
edge_scaling
|
float
|
global multiplier for edge tube thickness. default is 1.0. |
1.0
|
edge_cmap
|
str
|
colormap name for edges. default is 'coolwarm'. |
'coolwarm'
|
edge_color
|
str
|
constant color for all edges, overriding the colormap. |
None
|
edge_alpha
|
float
|
opacity of the edges (0.0 to 1.0). default is 1.0. |
1.0
|
edge_vminmax
|
list
|
[vmin, vmax] for edge colormap clipping. |
[None, None]
|
edge_curve
|
float
|
amount of bend applied to edges. 0.0 draws straight lines. default is 0.1. |
0.1
|
directed
|
bool
|
if true, renders asymmetrical connections (full matrix instead of upper triangle). |
False
|
style
|
str
|
lighting/shading preset ('default', 'matte', 'glossy', etc.). |
'default'
|
bmesh_type
|
str
|
surface to render as context (e.g., 'midthickness'). default is 'midthickness'. |
'midthickness'
|
bmesh_alpha
|
float
|
Opacity of the context brain mesh. Default is 0.15. |
0.15
|
bmesh_color
|
str
|
color of the context brain hull. default is 'lightgray'. |
'lightgray'
|
zoom
|
float
|
camera zoom level. default is 1.2. |
1.2
|
display_type
|
(matplotlib, interactive, pyvista, object)
|
'matplotlib': returns a matplotlib figure and axis (default). 'interactive': opens an interactive trame viewer in the browser. 'pyvista': returns a static jupyter widget (legacy behavior). 'object': returns the raw pyvista plotter object. |
'matplotlib'
|
export_path
|
str
|
path to save the exported image. |
None
|
Returns:
| Type | Description |
|---|---|
Axes or Plotter or DisplayObject
|
returns based on display_type: - 'matplotlib': returns a matplotlib axes object. - 'interactive': returns a trame browser viewer. - 'pyvista': returns a static jupyter widget. - 'object': returns the raw pyvista plotter. |
Source code in yabplot/plotting.py
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 | |
yabplot.plotting.clear_cache()
manually clears the global geometry cache to free ram.
Source code in yabplot/plotting.py
824 825 826 827 828 829 | |