.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_plotting/plot_haxby_masks.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_haxby_masks.py: Plot Haxby masks ================ Small script to show how to plot several masks at the same time. .. GENERATED FROM PYTHON SOURCE LINES 9-11 Load Haxby dataset ------------------ .. GENERATED FROM PYTHON SOURCE LINES 11-21 .. code-block:: Python from nilearn import datasets from nilearn.plotting import plot_anat, show haxby_dataset = datasets.fetch_haxby() # print basic information on the dataset print( f"First subject anatomical nifti image (3D) is at: {haxby_dataset.anat[0]}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none [fetch_haxby] Dataset directory found: /home/runner/work/nilearn/nilearn/nilearn_data/haxby2001 First subject anatomical nifti image (3D) is at: /home/runner/work/nilearn/nilearn/nilearn_data/haxby2001/subj2/anat.nii.gz .. GENERATED FROM PYTHON SOURCE LINES 22-26 Plot the masks -------------- Here we will generate a single legend using the trick described on https://matplotlib.org/2.0.2/users/legend_guide.html .. GENERATED FROM PYTHON SOURCE LINES 26-69 .. code-block:: Python import matplotlib.pyplot as plt from matplotlib.patches import Rectangle mask_vt_filename = haxby_dataset.mask_vt[0] mask_house_filename = haxby_dataset.mask_house[0] mask_face_filename = haxby_dataset.mask_face[0] masks = [ mask_vt_filename, mask_house_filename, mask_face_filename, ] colors = ["red", "blue", "limegreen"] z_slice = -14 fig = plt.figure(figsize=(4, 5.4), facecolor="k") display = plot_anat( haxby_dataset.anat[0], display_mode="z", cut_coords=[z_slice], figure=fig, ) for mask, color in zip(masks, colors, strict=False): display.add_contours( mask, antialiased=False, linewidth=4.0, levels=[0], colors=[color], ) p_v = Rectangle((0, 0), 1, 1, fc="red") p_h = Rectangle((0, 0), 1, 1, fc="blue") p_f = Rectangle((0, 0), 1, 1, fc="limegreen") plt.legend( [p_v, p_h, p_f], ["vt", "house", "face"], loc="lower right", ) show() .. image-sg:: /auto_examples/01_plotting/images/sphx_glr_plot_haxby_masks_001.png :alt: plot haxby masks :srcset: /auto_examples/01_plotting/images/sphx_glr_plot_haxby_masks_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.10/site-packages/nilearn/plotting/displays/_axes.py:98: UserWarning: The following kwargs were not used by contour: 'linewidth' .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.151 seconds) **Estimated memory usage:** 163 MB .. _sphx_glr_download_auto_examples_01_plotting_plot_haxby_masks.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.14.1?urlpath=lab/tree/notebooks/auto_examples/01_plotting/plot_haxby_masks.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_haxby_masks.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_haxby_masks.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_haxby_masks.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_