.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_plotting/plot_atlas.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` 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_atlas.py: Basic Atlas plotting ==================== Plot the regions of reference atlases. Check the :ref:`list of atlases ` to know which ones are shipped with Nilearn. .. GENERATED FROM PYTHON SOURCE LINES 12-14 Retrieving the atlas data ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 14-25 .. code-block:: Python from nilearn import datasets dataset_ho = datasets.fetch_atlas_harvard_oxford("cort-maxprob-thr25-2mm") atlas_ho_filename = dataset_ho.filename print(f"Atlas ROIs are located at: {atlas_ho_filename}") dataset_ju = datasets.fetch_atlas_juelich("maxprob-thr0-1mm") atlas_ju_filename = dataset_ju.filename print(f"Atlas ROIs are located at: {atlas_ju_filename}") .. rst-class:: sphx-glr-script-out .. code-block:: none [fetch_atlas_harvard_oxford] Dataset created in /home/runner/nilearn_data/fsl [fetch_atlas_harvard_oxford] Downloading data from https://www.nitrc.org/frs/download.php/9902/HarvardOxford.tgz ... [fetch_atlas_harvard_oxford] ...done. (0 seconds, 0 min) [fetch_atlas_harvard_oxford] Extracting data from /home/runner/nilearn_data/fsl/5c734f16e50cc772ef593cab9bb3137b/HarvardOxford.tgz ... [fetch_atlas_harvard_oxford] .. done. Atlas ROIs are located at: /home/runner/nilearn_data/fsl/data/atlases/HarvardOxford/HarvardOxford-cort-maxprob-thr25-2mm.nii.gz [fetch_atlas_juelich] Dataset found in /home/runner/nilearn_data/fsl [fetch_atlas_juelich] Downloading data from https://www.nitrc.org/frs/download.php/12096/Juelich.tgz ... [fetch_atlas_juelich] ...done. (0 seconds, 0 min) [fetch_atlas_juelich] Extracting data from /home/runner/nilearn_data/fsl/7e62e7e7fcc4d6e1428b6b2cb48f7a7c/Juelich.tgz... [fetch_atlas_juelich] .. done. Atlas ROIs are located at: /home/runner/nilearn_data/fsl/data/atlases/Juelich/Juelich-maxprob-thr0-1mm.nii.gz .. GENERATED FROM PYTHON SOURCE LINES 26-28 Visualizing the Harvard-Oxford atlas ------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 28-33 .. code-block:: Python from nilearn.plotting import plot_roi, show plot_roi(atlas_ho_filename, title="Harvard Oxford atlas") .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_001.png :alt: plot atlas :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 34-36 Visualizing the Juelich atlas ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python plot_roi(atlas_ju_filename, title="Juelich atlas") .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_002.png :alt: plot atlas :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-42 Visualizing the Harvard-Oxford atlas with contours -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: Python plot_roi( atlas_ho_filename, view_type="contours", title="Harvard Oxford atlas in contours", ) show() .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_003.png :alt: plot atlas :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/plotting/displays/_axes.py:94: UserWarning: No contour levels were found within the data range. im = getattr(ax, type)( .. GENERATED FROM PYTHON SOURCE LINES 50-52 Visualizing the Juelich atlas with contours ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 52-58 .. code-block:: Python plot_roi( atlas_ju_filename, view_type="contours", title="Juelich atlas in contours" ) show() .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_004.png :alt: plot atlas :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 59-78 Visualizing an atlas with its own colormap ------------------------------------------ Some atlases come with a look-up table that determines the color to use to represent each of its regions. You can pass this look-up table as a pandas dataframe to the ``cmap`` argument to use its colormap. .. admonition:: Look-up table format :class: tip The look-up table must be formatted according to the BIDS standard. and that the colors must be in ``color`` column using hexadecimal values. If an invalid look-up table is passed, a warning will be thrown and the ``plot_roi`` function will fall back to using its default colormap. .. GENERATED FROM PYTHON SOURCE LINES 80-82 Here we are using the Yeo atlas that comes with a predefined colormap. .. GENERATED FROM PYTHON SOURCE LINES 82-86 .. code-block:: Python dataset_yeo = datasets.fetch_atlas_yeo_2011(n_networks=17) print(dataset_yeo.lut) .. rst-class:: sphx-glr-script-out .. code-block:: none [fetch_atlas_yeo_2011] Dataset found in /home/runner/nilearn_data/yeo_2011 index name color 0 0 Background #000000 1 1 17Networks_1 #781286 2 2 17Networks_2 #ff0000 3 3 17Networks_3 #4682b4 4 4 17Networks_4 #2acca4 5 5 17Networks_5 #4a9b3c 6 6 17Networks_6 #00760e 7 7 17Networks_7 #c43afa 8 8 17Networks_8 #ff98d5 9 9 17Networks_9 #dcf8a4 10 10 17Networks_10 #7a8732 11 11 17Networks_11 #778cb0 12 12 17Networks_12 #e69422 13 13 17Networks_13 #87324a 14 14 17Networks_14 #0c30ff 15 15 17Networks_15 #000082 16 16 17Networks_16 #ffff00 17 17 17Networks_17 #cd3e4e .. GENERATED FROM PYTHON SOURCE LINES 87-88 Let's compare the atlas with the default colormap and its own colormap. .. GENERATED FROM PYTHON SOURCE LINES 88-103 .. code-block:: Python plot_roi( dataset_yeo.maps, title="Yeo atlas", colorbar=True, ) plot_roi( dataset_yeo.maps, title="Yeo atlas with its own colors", cmap=dataset_yeo.lut, colorbar=True, ) show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_005.png :alt: plot atlas :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_006.png :alt: plot atlas :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_atlas_006.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 8.877 seconds) **Estimated memory usage:** 455 MB .. _sphx_glr_download_auto_examples_01_plotting_plot_atlas.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/nilearn/nilearn/0.12.0?urlpath=lab/tree/notebooks/auto_examples/01_plotting/plot_atlas.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_atlas.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_atlas.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_atlas.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_