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()
# 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 created in
/home/runner/nilearn_data/brainomics_localizer
[fetch_single_file] Downloading data from https://osf.io/hwbm2/download ...
[fetch_single_file] ...done. (1 seconds, 0 min)
[fetch_single_file] Downloading data from
https://osf.io/download/5d27ddc91c5b4a001b9ef9d0/ ...
[fetch_single_file] ...done. (2 seconds, 0 min)
[fetch_single_file] Downloading data from
https://osf.io/download/5d27d29145253a001c3e284f/ ...
[fetch_single_file] ...done. (2 seconds, 0 min)
[fetch_single_file] Downloading data from
https://osf.io/download/5d275ede1c5b4a001aa00c26/ ...
[_chunk_report_] Downloaded 5931008 of 13951266 bytes (42.5%%, 1.4s
remaining)
[fetch_single_file] ...done. (2 seconds, 0 min)
[fetch_single_file] Downloading data from
https://osf.io/download/5d27037f45253a001c3d4563/ ...
[fetch_single_file] ...done. (1 seconds, 0 min)
[fetch_single_file] Downloading data from
https://osf.io/download/5d7b8948fcbf44001c44e695/ ...
[fetch_single_file] ...done. (1 seconds, 0 min)
Plotting with enhancement of background image with dim=-.5¶
from nilearn.plotting import plot_stat_map, show
cut_coords = (36, -27, 66)
plot_stat_map(
localizer_tmap_filename,
bg_img=localizer_anat_filename,
cut_coords=cut_coords,
threshold=3,
title="dim=-.5",
dim=-0.5,
)
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7ff015fbedc0>
Plotting with no change of contrast in background image with dim=0¶
plot_stat_map(
localizer_tmap_filename,
bg_img=localizer_anat_filename,
cut_coords=cut_coords,
threshold=3,
title="dim=0",
dim=0,
)
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7ff016188550>
Plotting with decrease of contrast in background image with dim=.5¶
plot_stat_map(
localizer_tmap_filename,
bg_img=localizer_anat_filename,
cut_coords=cut_coords,
threshold=3,
title="dim=.5",
dim=0.5,
)
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7ff0163f5400>
Plotting with more decrease in contrast with dim=1¶
plot_stat_map(
localizer_tmap_filename,
bg_img=localizer_anat_filename,
cut_coords=cut_coords,
threshold=3,
title="dim=1",
dim=1,
)
show()
Total running time of the script: (0 minutes 16.067 seconds)
Estimated memory usage: 107 MB