1"""
2Plot Haxby masks
3=================
4
5Small script to plot the masks of the Haxby dataset.
6"""
7import matplotlib.pyplot as plt
8
9from nilearn import datasets
10haxby_dataset = datasets.fetch_haxby()
11
12# print basic information on the dataset
13print('First subject anatomical nifti image (3D) is at: %s' %
14      haxby_dataset.anat[0])
15print('First subject functional nifti image (4D) is at: %s' %
16      haxby_dataset.func[0])  # 4D data
17
18# Build the mean image because we have no anatomic data
19from nilearn import image
20func_filename = haxby_dataset.func[0]
21mean_img = image.mean_img(func_filename)
22
23z_slice = -14
24
25fig = plt.figure(figsize=(4, 5.4), facecolor='k')
26
27from nilearn.plotting import plot_anat, show
28display = plot_anat(mean_img, display_mode='z', cut_coords=[z_slice],
29                    figure=fig)
30mask_vt_filename = haxby_dataset.mask_vt[0]
31mask_house_filename = haxby_dataset.mask_house[0]
32mask_face_filename = haxby_dataset.mask_face[0]
33display.add_contours(mask_vt_filename, contours=1, antialiased=False,
34                     linewidths=4., levels=[0], colors=['red'])
35display.add_contours(mask_house_filename, contours=1, antialiased=False,
36                     linewidths=4., levels=[0], colors=['blue'])
37display.add_contours(mask_face_filename, contours=1, antialiased=False,
38                     linewidths=4., levels=[0], colors=['limegreen'])
39
40# We generate a legend using the trick described on
41# http://matplotlib.sourceforge.net/users/legend_guide.httpml#using-proxy-artist
42from matplotlib.patches import Rectangle
43p_v = Rectangle((0, 0), 1, 1, fc="red")
44p_h = Rectangle((0, 0), 1, 1, fc="blue")
45p_f = Rectangle((0, 0), 1, 1, fc="limegreen")
46plt.legend([p_v, p_h, p_f], ["vt", "house", "face"])
47
48show()
49