plot styling¶
yabplot provides several styling presets and customization options to make your figures publication-ready.
in this tutorial, we will explore:
- lighting styles.
- customizing the background context brain.
- handling missing data (
nan_color,nan_alpha). - tract-specific visualizations.
In [1]:
Copied!
import yabplot as yab
import matplotlib.pyplot as plt
import numpy as np
import yabplot as yab
import matplotlib.pyplot as plt
import numpy as np
1. lighting styles¶
different styles can highlight shape (sculpted) or data values (flat/matte). available styles include: 'default', 'matte', 'glossy', 'sculpted', 'flat'.
In [12]:
Copied!
# generate random data for demonstration
regions = yab.get_atlas_regions('aseg', 'subcortical')
data = np.random.rand(len(regions))
fig, axes = plt.subplots(3, 1, figsize=(8, 8), dpi=200)
# compare 'flat' vs 'glossy' vs 'matte' styles
# - glossy enhances the 3d curvature giving it a shiny look
# - flat is great for seeing exact data colors without shadows
# - matte is a balance between both
for i, style in enumerate(['glossy', 'flat', 'matte']):
axes[i] = yab.plot_subcortical(
data=data,
ax = axes[i],
cmap='viridis',
atlas='aseg',
views=['left_lateral', 'superior', 'anterior'],
style=style
)
axes[i].set_title(style, fontsize=7)
# generate random data for demonstration
regions = yab.get_atlas_regions('aseg', 'subcortical')
data = np.random.rand(len(regions))
fig, axes = plt.subplots(3, 1, figsize=(8, 8), dpi=200)
# compare 'flat' vs 'glossy' vs 'matte' styles
# - glossy enhances the 3d curvature giving it a shiny look
# - flat is great for seeing exact data colors without shadows
# - matte is a balance between both
for i, style in enumerate(['glossy', 'flat', 'matte']):
axes[i] = yab.plot_subcortical(
data=data,
ax = axes[i],
cmap='viridis',
atlas='aseg',
views=['left_lateral', 'superior', 'anterior'],
style=style
)
axes[i].set_title(style, fontsize=7)
2. context brain (bmesh)¶
for subcortical and tract plots, a context brain mesh is rendered to show anatomical location. you can change its style or hide it.
In [15]:
Copied!
# styling the context brain
ax = yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
bmesh='midthickness', # standard surface
bmesh_alpha=0.25, # less transparent
bmesh_color='gray', # dark background mesh
)
ax = yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
bmesh='inflated', # inflated surface
bmesh_alpha=0.1, # very transparent
bmesh_color='gray', # dark background mesh
)
# hiding the context brain
ax = yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
bmesh=None, # no context surface
)
# styling the context brain
ax = yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
bmesh='midthickness', # standard surface
bmesh_alpha=0.25, # less transparent
bmesh_color='gray', # dark background mesh
)
ax = yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
bmesh='inflated', # inflated surface
bmesh_alpha=0.1, # very transparent
bmesh_color='gray', # dark background mesh
)
# hiding the context brain
ax = yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
bmesh=None, # no context surface
)
3. handling missing data (nan)¶
when plotting dictionaries or incomplete arrays, you can control how missing regions appear using nan_color and nan_alpha.
In [19]:
Copied!
# define data for only one region
sparse_data = {'Left-Putamen': 1.0}
ax = yab.plot_subcortical(
data=sparse_data,
atlas='aseg',
# make missing regions white and almost transparent
nan_color='gray',
nan_alpha=0.05,
style='matte'
)
# define data for only one region
sparse_data = {'Left-Putamen': 1.0}
ax = yab.plot_subcortical(
data=sparse_data,
atlas='aseg',
# make missing regions white and almost transparent
nan_color='gray',
nan_alpha=0.05,
style='matte'
)
Context leak detected, CoreAnalytics returned false
4. tract customization¶
for white matter tracts, you can pass specific parameters to pyvista to change the rendering of lines/tubes via tract_kwargs.
In [18]:
Copied!
# render tracts as thin lines instead of 3d tubes (faster, different look)
ax = yab.plot_tracts(
atlas='xtract_medium',
orientation_coloring=True,
bmesh='pial',
tract_kwargs={
'render_lines_as_tubes': False, # simple lines
'line_width': 2.0 # slightly thicker lines
},
)
# render as thick tubes
ax = yab.plot_tracts(
atlas='xtract_medium',
orientation_coloring=True,
bmesh='inflated',
tract_kwargs={
'render_lines_as_tubes': True,
'line_width': 4.0 # very thick tubes
},
)
# render tracts as thin lines instead of 3d tubes (faster, different look)
ax = yab.plot_tracts(
atlas='xtract_medium',
orientation_coloring=True,
bmesh='pial',
tract_kwargs={
'render_lines_as_tubes': False, # simple lines
'line_width': 2.0 # slightly thicker lines
},
)
# render as thick tubes
ax = yab.plot_tracts(
atlas='xtract_medium',
orientation_coloring=True,
bmesh='inflated',
tract_kwargs={
'render_lines_as_tubes': True,
'line_width': 4.0 # very thick tubes
},
)