Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Glass brain plotting in nilearn¶
See Plotting brain images for more plotting functionalities.
Load data¶
from nilearn import datasets
stat_img = datasets.load_sample_motor_activation_image()
Glass brain plotting: whole brain sagittal cuts¶
from nilearn import plotting
plotting.plot_glass_brain(stat_img, threshold=3)

<nilearn.plotting.displays._projectors.OrthoProjector object at 0x7f0fe96b2e90>
Glass brain plotting: black background¶
On a black background (option “black_bg”), and with only the x and the z view (option “display_mode”).
plotting.plot_glass_brain(
stat_img,
title="plot_glass_brain",
black_bg=True,
display_mode="xz",
threshold=3,
)

<nilearn.plotting.displays._projectors.XZProjector object at 0x7f0fe950e290>
Glass brain plotting: Hemispheric sagittal cuts¶
plotting.plot_glass_brain(
stat_img,
title='plot_glass_brain with display_mode="lyrz"',
display_mode="lyrz",
threshold=3,
)
plotting.show()

/home/runner/work/nilearn/nilearn/examples/01_plotting/plot_demo_glass_brain.py:47: UserWarning: You are using the 'agg' matplotlib backend that is non-interactive.
No figure will be plotted when calling matplotlib.pyplot.show() or nilearn.plotting.show().
You can fix this by installing a different backend: for example via
pip install PyQt6
plotting.show()
Total running time of the script: (0 minutes 4.540 seconds)
Estimated memory usage: 101 MB