.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_plotting/plot_visualization.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_visualization.py: NeuroImaging volumes visualization ================================== Simple example to show Nifti data visualization. .. GENERATED FROM PYTHON SOURCE LINES 9-11 Fetch data ---------- .. GENERATED FROM PYTHON SOURCE LINES 11-24 .. code-block:: Python from nilearn import datasets # By default 2nd subject will be fetched haxby_dataset = datasets.fetch_haxby() # print basic information on the dataset print( f"First anatomical nifti image (3D) located is at: {haxby_dataset.anat[0]}" ) print( f"First functional nifti image (4D) is located at: {haxby_dataset.func[0]}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none First anatomical nifti image (3D) located is at: /home/himanshu/nilearn_data/haxby2001/subj2/anat.nii.gz First functional nifti image (4D) is located at: /home/himanshu/nilearn_data/haxby2001/subj2/bold.nii.gz .. GENERATED FROM PYTHON SOURCE LINES 25-27 Visualization ------------- .. GENERATED FROM PYTHON SOURCE LINES 27-37 .. code-block:: Python from nilearn.image.image import mean_img # Compute the mean EPI: we do the mean along the axis 3, which is time func_filename = haxby_dataset.func[0] mean_haxby = mean_img(func_filename) from nilearn.plotting import plot_epi, show plot_epi(mean_haxby, colorbar=True, cbar_tick_format="%i") .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_visualization_001.png :alt: plot visualization :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_visualization_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 38-41 Extracting a brain mask ----------------------- Simple computation of a mask from the :term:`fMRI` data .. GENERATED FROM PYTHON SOURCE LINES 41-50 .. code-block:: Python from nilearn.masking import compute_epi_mask mask_img = compute_epi_mask(func_filename) # Visualize it as an ROI from nilearn.plotting import plot_roi plot_roi(mask_img, mean_haxby) .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_visualization_002.png :alt: plot visualization :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_visualization_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 51-53 Applying the mask to extract the corresponding time series ---------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 53-72 .. code-block:: Python from nilearn.masking import apply_mask masked_data = apply_mask(func_filename, mask_img) # masked_data shape is (timepoints, voxels). We can plot the first 150 # timepoints from two voxels # And now plot a few of these import matplotlib.pyplot as plt plt.figure(figsize=(7, 5)) plt.plot(masked_data[:150, :2]) plt.xlabel("Time [TRs]", fontsize=16) plt.ylabel("Intensity", fontsize=16) plt.xlim(0, 150) plt.subplots_adjust(bottom=0.12, top=0.95, right=0.95, left=0.12) show() .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_visualization_003.png :alt: plot visualization :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_visualization_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 16.719 seconds) **Estimated memory usage:** 1360 MB .. _sphx_glr_download_auto_examples_01_plotting_plot_visualization.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_visualization.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_visualization.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_visualization.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_