Note
Go to the end to download the full example code. or to run this example in your browser via Binder
Controlling the contrast of the background when plotting¶
The dim argument controls the contrast of the background.
dim modifies the contrast of this image: dim=0 leaves the image unchanged, negative values of dim enhance it, and positive values decrease it (dim the background).
This dim argument may also be useful for the plot_roi function used to display ROIs on top of a background image.
Retrieve the data: the localizer dataset with contrast maps¶
from nilearn import datasets
localizer_dataset = datasets.fetch_localizer_button_task(legacy_format=False)
# Contrast map of motor task
localizer_tmap_filename = localizer_dataset.tmap
# Subject specific anatomical image
localizer_anat_filename = localizer_dataset.anat
[get_dataset_dir] Dataset found in /home/runner/work/nilearn/nilearn/nilearn_data/brainomics_localizer
Plotting with enhancement of background image with dim=-.5¶
from nilearn import plotting
plotting.plot_stat_map(
localizer_tmap_filename,
bg_img=localizer_anat_filename,
cut_coords=(36, -27, 66),
threshold=3,
title="dim=-.5",
dim=-0.5,
)
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7f42ae916390>
Plotting with no change of contrast in background image with dim=0¶
plotting.plot_stat_map(
localizer_tmap_filename,
bg_img=localizer_anat_filename,
cut_coords=(36, -27, 66),
threshold=3,
title="dim=0",
dim=0,
)
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7f42c11702c0>
Plotting with decrease of contrast in background image with dim=.5¶
plotting.plot_stat_map(
localizer_tmap_filename,
bg_img=localizer_anat_filename,
cut_coords=(36, -27, 66),
threshold=3,
title="dim=.5",
dim=0.5,
)
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7f42c138f560>
Plotting with more decrease in contrast with dim=1¶
plotting.plot_stat_map(
localizer_tmap_filename,
bg_img=localizer_anat_filename,
cut_coords=(36, -27, 66),
threshold=3,
title="dim=1",
dim=1,
)
plotting.show()
Total running time of the script: (0 minutes 5.073 seconds)
Estimated memory usage: 227 MB