Glass brain plotting in nilearn (all options)#
The first part of this example goes through different options of the
plot_glass_brain function (including plotting
The second part goes through same options but selected of the same glass brain function but plotting is seen with contours.
nilearn.datasets.fetch_neurovault_motor_task for details
about the plotting data and associated meta-data.
Load the data#
We will use a motor activation contrast map distributed with Nilearn.
Demo glass brain plotting#
plot_glass_brain uses a display mode
called ‘ortho’ which results in three projections. It is equivalent to
plot_glass_brain. Note that depending on the
display_mode, different display objects are returned. Here,
OrthoProjector is returned.
<nilearn.plotting.displays._projectors.OrthoProjector object at 0x7fd1f296ec90>
The same figure, with a colorbar, can be produced by
<nilearn.plotting.displays._projectors.OrthoProjector object at 0x7fd1f01da510>
Here, we show how to set a black background, and we only view sagittal and
axial projections by setting
display_mode='xz', which returns a
<nilearn.plotting.displays._projectors.XZProjector object at 0x7fd1f23d2790>
We can also plot the sign of the activation by setting
Additionally, we only visualize coronal and axial projections by setting
display_mode='yz' which returns a
<nilearn.plotting.displays._projectors.YZProjector object at 0x7fd1e346fd50>
display_mode='yx' (returns a
<nilearn.plotting.displays._projectors.YXProjector object at 0x7fd1efb6dbd0>
Different projections for the left and right hemispheres#
In the previous section we saw a few projection modes, which are controlled
by setting the argument
plot_glass_brain. In this section, we will show
some additional possibilities. For example, setting
enables an hemispheric sagittal view. The display object returned is then a
<nilearn.plotting.displays._projectors.LZRProjector object at 0x7fd1e3595250>
display_mode='lyrz' returns a
<nilearn.plotting.displays._projectors.LYRZProjector object at 0x7fd1effc2a10>
If you are only interested in single projections, you can set
display_mode to ‘x’ (returns a
XProjector), ‘y’ (returns a
YProjector), ‘z’ (returns a
ZProjector), ‘l’ (returns a
LProjector), or ‘r’ (returns a
<nilearn.plotting.displays._projectors.XProjector object at 0x7fd1f299fd50>
Demo glass brain plotting with contours and with fillings#
In this example, we focus on using methods
title. First, we
save the display object (here a
LZRYProjector) into a variable named
display. Note that we set the first argument to
None since we
want an empty glass brain to plot the statistical maps with
We can fill the contours by setting
filled=True. Note that we are not
specifying levels here
Here, we input a specific level (cut-off) in the statistical map. In other words, we are thresholding our statistical map.
We set the threshold using a parameter of method
levels which value is given as a list and we choose the color to be red.
Plotting with same demonstration but fill the contours (by setting
Plotting with black background,
black_bg should be set to
Black background plotting with filled in contours.
Display contour projections in both hemispheres#
The key argument to vary here is
display_mode for hemispheric plotting.
Here, we set
display_mode='lr' for both hemispheric plots. Note that a
LRProjector is returned.
Filled contours in both hemispheric plotting, by adding
With positive and negative signs of activations with
By default parameter
True and sign of activations
can be displayed by changing
False. Note that we also
display_mode='lyr' which returns a
LYRProjector display object.
filled=True to get positive and negative sign activations
with fillings in the contours.
Displaying both signs (positive and negative) of activations with threshold
meaning thresholding by adding an argument
levels in method
We give two values through the argument
levels which corresponds to the
thresholds of the contour we want to draw: One is positive and the other one
is negative. We give a list of
colors as argument to associate a
different color to each contour. Additionally, we also choose to plot
contours with thick line widths. For
linewidths, one value would be
enough so that same value is used for both contours.
Same display demonstration as above but adding
filled=True to get
fillings inside the contours.
Unlike in previous plot, here we specify each sign at a time. We call negative values display first followed by positive values display.
First, we fetch our display object with same parameters used as above. Then, we plot negative sign of activation with levels given as negative activation value in a list. Upper bound should be kept to -infinity. Next, using the same display object, we plot positive sign of activation.
display = plot_glass_brain(None, plot_abs=False, display_mode="lzry") display.add_contours(stat_img, filled=True, levels=[-np.inf, -2.8], colors="b") display.add_contours(stat_img, filled=True, levels=[3.0], colors="r") display.title("Now same plotting but with filled contours") # Finally, displaying them plotting.show()
Total running time of the script: (0 minutes 30.441 seconds)
Estimated memory usage: 8 MB