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 [ ]:
Copied!
import yabplot as yab
import numpy as np
import yabplot as yab
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 [23]:
Copied!
# generate random data for demonstration
regions = yab.get_atlas_regions('aseg', 'subcortical')
data = np.random.rand(len(regions))
# compare 'flat' vs 'glossy' vs 'matte' styles
# glossy enhances the 3d curvature giving it a shiny look
yab.plot_subcortical(
data=data,
cmap='viridis',
atlas='aseg',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
style='glossy'
)
# flat is great for seeing exact data colors without shadows
yab.plot_subcortical(
data=data,
cmap='viridis',
atlas='aseg',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
style='flat'
)
# matte is a balance between both
yab.plot_subcortical(
data=data,
cmap='viridis',
atlas='aseg',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
style='matte'
)
# generate random data for demonstration
regions = yab.get_atlas_regions('aseg', 'subcortical')
data = np.random.rand(len(regions))
# compare 'flat' vs 'glossy' vs 'matte' styles
# glossy enhances the 3d curvature giving it a shiny look
yab.plot_subcortical(
data=data,
cmap='viridis',
atlas='aseg',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
style='glossy'
)
# flat is great for seeing exact data colors without shadows
yab.plot_subcortical(
data=data,
cmap='viridis',
atlas='aseg',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
style='flat'
)
# matte is a balance between both
yab.plot_subcortical(
data=data,
cmap='viridis',
atlas='aseg',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
style='matte'
)
Out[23]:
<pyvista.plotting.plotter.Plotter at 0x335103510>
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 [24]:
Copied!
# styling the context brain
yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
bmesh_type='conte69', # standard surface
bmesh_alpha=0.05, # very transparent (ghost-like)
bmesh_color='black', # dark background mesh
style='default',
display_type='static'
)
# hiding the context brain
yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
bmesh_type=None, # no context surface
style='default',
display_type='static'
)
# styling the context brain
yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
bmesh_type='conte69', # standard surface
bmesh_alpha=0.05, # very transparent (ghost-like)
bmesh_color='black', # dark background mesh
style='default',
display_type='static'
)
# hiding the context brain
yab.plot_subcortical(
atlas='brainnetome_sc',
views=['left_lateral', 'superior', 'anterior'],
figsize=(1200, 400),
bmesh_type=None, # no context surface
style='default',
display_type='static'
)
Out[24]:
<pyvista.plotting.plotter.Plotter at 0x3569a8250>
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 [25]:
Copied!
# define data for only one region
sparse_data = {'Left_Putamen': 1.0}
yab.plot_subcortical(
data=sparse_data,
atlas='aseg',
# make missing regions white and fully opaque (solid)
nan_color='white',
nan_alpha=0.5,
style='matte',
display_type='static'
)
# define data for only one region
sparse_data = {'Left_Putamen': 1.0}
yab.plot_subcortical(
data=sparse_data,
atlas='aseg',
# make missing regions white and fully opaque (solid)
nan_color='white',
nan_alpha=0.5,
style='matte',
display_type='static'
)
Out[25]:
<pyvista.plotting.plotter.Plotter at 0x388326bd0>
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 [26]:
Copied!
# render tracts as thin lines instead of 3d tubes (faster, different look)
yab.plot_tracts(
atlas='xtract_tiny',
orientation_coloring=True,
tract_kwargs={
'render_lines_as_tubes': False, # simple lines
'line_width': 2.0 # slightly thicker lines
},
display_type='static'
)
# render as thick tubes
yab.plot_tracts(
atlas='xtract_tiny',
orientation_coloring=True,
tract_kwargs={
'render_lines_as_tubes': True,
'line_width': 4.0 # very thick tubes
},
display_type='static'
)
# render tracts as thin lines instead of 3d tubes (faster, different look)
yab.plot_tracts(
atlas='xtract_tiny',
orientation_coloring=True,
tract_kwargs={
'render_lines_as_tubes': False, # simple lines
'line_width': 2.0 # slightly thicker lines
},
display_type='static'
)
# render as thick tubes
yab.plot_tracts(
atlas='xtract_tiny',
orientation_coloring=True,
tract_kwargs={
'render_lines_as_tubes': True,
'line_width': 4.0 # very thick tubes
},
display_type='static'
)
Out[26]:
<pyvista.plotting.plotter.Plotter at 0x105db4c50>