.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_plotting/plot_demo_plotting.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_demo_plotting.py: Plotting tools in nilearn ========================= Nilearn comes with a set of plotting functions for easy visualization of Nifti-like images such as statistical maps mapped onto anatomical images or onto glass brain representation, anatomical images, functional/EPI images, region specific mask images. See :ref:`plotting` for more details. .. GENERATED FROM PYTHON SOURCE LINES 14-16 Retrieve data from nilearn provided (general-purpose) datasets -------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 16-40 .. code-block:: Python from nilearn import datasets # haxby dataset to have EPI images and masks haxby_dataset = datasets.fetch_haxby() # print basic information on the dataset print( "First subject anatomical nifti image (3D) is " f"at: {haxby_dataset.anat[0]}" ) print( "First subject functional nifti image (4D) is " f"at: {haxby_dataset.func[0]}" ) haxby_anat_filename = haxby_dataset.anat[0] haxby_mask_filename = haxby_dataset.mask_vt[0] haxby_func_filename = haxby_dataset.func[0] # one motor activation map stat_img = datasets.load_sample_motor_activation_image() .. rst-class:: sphx-glr-script-out .. code-block:: none First subject anatomical nifti image (3D) is at: /home/himanshu/nilearn_data/haxby2001/subj2/anat.nii.gz First subject functional nifti image (4D) is at: /home/himanshu/nilearn_data/haxby2001/subj2/bold.nii.gz .. GENERATED FROM PYTHON SOURCE LINES 41-43 Plotting statistical maps with function `plot_stat_map` ------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 43-63 .. code-block:: Python from nilearn import plotting # Visualizing t-map image on EPI template with manual # positioning of coordinates using cut_coords given as a list plotting.plot_stat_map( stat_img, threshold=3, title="plot_stat_map", cut_coords=[36, -27, 66] ) # It's also possible to visualize volumes in a LR-flipped "radiological" view # Just set radiological=True plotting.plot_stat_map( stat_img, threshold=3, title="plot_stat_map", cut_coords=[36, -27, 66], radiological=True, ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_001.png :alt: plot demo plotting :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_002.png :alt: plot demo plotting :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 64-70 Making interactive visualizations with function `view_img` ---------------------------------------------------------- An alternative to :func:`nilearn.plotting.plot_stat_map` is to use :func:`nilearn.plotting.view_img` that gives more interactive visualizations in a web browser. See :ref:`interactive-stat-map-plotting` for more details. .. GENERATED FROM PYTHON SOURCE LINES 70-76 .. code-block:: Python view = plotting.view_img(stat_img, threshold=3) # In a Jupyter notebook, if ``view`` is the output of a cell, it will # be displayed below the cell view .. rst-class:: sphx-glr-script-out .. code-block:: none /home/himanshu/.local/miniconda3/envs/nilearnpy/lib/python3.12/site-packages/numpy/core/fromnumeric.py:771: UserWarning: Warning: 'partition' will ignore the 'mask' of the MaskedArray. a.partition(kth, axis=axis, kind=kind, order=order) .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 77-82 .. code-block:: Python # uncomment this to open the plot in a web browser: # view.open_in_browser() .. GENERATED FROM PYTHON SOURCE LINES 83-88 Plotting statistical maps in a glass brain with function `plot_glass_brain` --------------------------------------------------------------------------- Now, the t-map image is mapped on glass brain representation where glass brain is always a fixed background template .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. code-block:: Python plotting.plot_glass_brain(stat_img, title="plot_glass_brain", threshold=3) .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_003.png :alt: plot demo plotting :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 91-95 Plotting anatomical images with function `plot_anat` ---------------------------------------------------- Visualizing anatomical image of haxby dataset .. GENERATED FROM PYTHON SOURCE LINES 95-97 .. code-block:: Python plotting.plot_anat(haxby_anat_filename, title="plot_anat") .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_004.png :alt: plot demo plotting :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 98-104 Plotting ROIs (here the mask) with function `plot_roi` ------------------------------------------------------ Visualizing ventral temporal region image from haxby dataset overlaid on subject specific anatomical image with coordinates positioned automatically on region of interest (roi) .. GENERATED FROM PYTHON SOURCE LINES 104-108 .. code-block:: Python plotting.plot_roi( haxby_mask_filename, bg_img=haxby_anat_filename, title="plot_roi" ) .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_005.png :alt: plot demo plotting :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 109-111 Plotting :term:`EPI` image with function `plot_epi` --------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 111-122 .. code-block:: Python # Import image processing tool from nilearn import image # Compute the voxel_wise mean of functional images across time. # Basically reducing the functional image from 4D to 3D mean_haxby_img = image.mean_img(haxby_func_filename) # Visualizing mean image (3D) plotting.plot_epi(mean_haxby_img, title="plot_epi") .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_006.png :alt: plot demo plotting :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 123-125 A call to plotting.show is needed to display the plots when running in script mode (ie outside IPython) .. GENERATED FROM PYTHON SOURCE LINES 125-127 .. code-block:: Python plotting.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 13.851 seconds) **Estimated memory usage:** 916 MB .. _sphx_glr_download_auto_examples_01_plotting_plot_demo_plotting.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/main?urlpath=lab/tree/notebooks/auto_examples/01_plotting/plot_demo_plotting.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_demo_plotting.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_demo_plotting.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_