.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code or to run this example in your browser via Binder
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_auto_examples_01_plotting_plot_overlay.py:
Visualizing a probablistic atlas: the default mode in the MSDL atlas
=====================================================================
Visualizing a probablistic atlas requires visualizing the different
maps that compose it.
Here we represent the nodes constituting the default mode network in the
`MSDL atlas
`_.
The tools that we need to leverage are:
* :func:`nilearn.image.index_img` to retrieve the various maps composing
the atlas
* Adding overlays on an existing brain display, to plot each of these
maps
Alternatively, :func:`nilearn.plotting.plot_prob_atlas` allows to plot the maps in one step that
with less control over the plot (see below)
Fetching probabilistic atlas - MSDL atlas
-----------------------------------------
.. code-block:: default
from nilearn import datasets
atlas_data = datasets.fetch_atlas_msdl()
atlas_filename = atlas_data.maps
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
Dataset created in /home/varoquau/nilearn_data/msdl_atlas
Downloading data from https://team.inria.fr/parietal/files/2015/01/MSDL_rois.zip ...
...done. (0 seconds, 0 min)
Extracting data from /home/varoquau/nilearn_data/msdl_atlas/8eaecb9e05c478f565847000d9902a25/MSDL_rois.zip..... done.
/usr/lib/python3/dist-packages/numpy/lib/npyio.py:2358: VisibleDeprecationWarning: Reading unicode strings without specifying the encoding argument is deprecated. Set the encoding, use None for the system default.
output = genfromtxt(fname, **kwargs)
Visualizing a probabilistic atlas with plot_stat_map and add_overlay object
---------------------------------------------------------------------------
.. code-block:: default
from nilearn import plotting, image
# First plot the map for the PCC: index 4 in the atlas
display = plotting.plot_stat_map(image.index_img(atlas_filename, 4),
colorbar=False,
title="DMN nodes in MSDL atlas")
# Now add as an overlay the maps for the ACC and the left and right
# parietal nodes
display.add_overlay(image.index_img(atlas_filename, 5),
cmap=plotting.cm.black_blue)
display.add_overlay(image.index_img(atlas_filename, 6),
cmap=plotting.cm.black_green)
display.add_overlay(image.index_img(atlas_filename, 3),
cmap=plotting.cm.black_pink)
plotting.show()
.. image:: /auto_examples/01_plotting/images/sphx_glr_plot_overlay_001.png
:alt: plot overlay
:class: sphx-glr-single-img
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
/usr/lib/python3/dist-packages/numpy/ma/core.py:2785: UserWarning: Warning: converting a masked element to nan.
_data = np.array(data, dtype=dtype, copy=copy,
Visualizing a probablistic atlas with plot_prob_atlas
=====================================================
Alternatively, we can create a new 4D-image by selecting the 3rd, 4th, 5th and 6th (zero-based) probabilistic map from atlas
via :func:`nilearn.image.index_img` and use :func:`nilearn.plotting.plot_prob_atlas` (added in version 0.2)
to plot the selected nodes in one step.
Unlike :func:`nilearn.plotting.plot_stat_map` this works with 4D images
.. code-block:: default
dmn_nodes = image.index_img(atlas_filename, [3, 4, 5, 6])
# Note that dmn_node is now a 4D image
print(dmn_nodes.shape)
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
(40, 48, 35, 4)
.. code-block:: default
display = plotting.plot_prob_atlas(dmn_nodes,
cut_coords=(0, -55, 29),
title="DMN nodes in MSDL atlas")
plotting.show()
.. image:: /auto_examples/01_plotting/images/sphx_glr_plot_overlay_002.png
:alt: plot overlay
:class: sphx-glr-single-img
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 2.943 seconds)
.. _sphx_glr_download_auto_examples_01_plotting_plot_overlay.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: binder-badge
.. image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/nilearn/nilearn.github.io/master?filepath=examples/auto_examples/01_plotting/plot_overlay.ipynb
:width: 150 px
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plot_overlay.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_overlay.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_