Repository: nilearn/nilearn

Issue:
Visualization example is too big
The visualization example downloads quite a lot of data and generates too many images. We should break it in several small examples, in particular for the (amazing) glass brain.



Discussion:
The "quite a lot of data" got fixed in #320. Not sure it is still worth splitting the examples in different files. Personally I find it quite nice to have the main plotting function variations in the same file, rather than having to look through a few files to find the one you are after.

> The "quite a lot of data" got fixed in #320. Not sure it is still worth
> splitting the examples in different files.

OK, but we should have at least one very simple example that generates
the figure on the first page of the project. That way people don't get
frightened.

G

Sorry, I see your point just now: people clicking on the glass brain picture on the home page should be redirected to a simpler script because they probably don't care about all the different variations on plotting.

Maybe break down examples in the simplest then. I'd probably go for breakdown by function (plot_stat_map, plot_glass_brain, plot_roi, plot_epi, ...) + one for more advanced stuff where you get a display object and use add_overlay, add_contours, add_edges on it.


Resolving patch:
diff --git a/examples/manipulating_visualizing/plot_demo_more_plotting.py b/examples/manipulating_visualizing/plot_demo_more_plotting.py
new file mode 100644
--- /dev/null
+++ b/examples/manipulating_visualizing/plot_demo_more_plotting.py
@@ -0,0 +1,87 @@
+"""
+More nilearn plotting
+=====================
+
+See :ref:`plotting` for more details.
+"""
+
+from nilearn import datasets
+from nilearn import plotting, image
+
+###############################################################################
+# Retrieve the data: haxby dataset to have EPI images and masks, and
+# localizer dataset to have contrast maps
+
+haxby_dataset = datasets.fetch_haxby(n_subjects=1)
+haxby_anat_filename = haxby_dataset.anat[0]
+haxby_mask_filename = haxby_dataset.mask_vt[0]
+haxby_func_filename = haxby_dataset.func[0]
+
+localizer_dataset = datasets.fetch_localizer_contrasts(
+    ["left vs right button press"],
+    n_subjects=4,
+    get_anats=True)
+localizer_anat_filename = localizer_dataset.anats[3]
+localizer_cmap_filename = localizer_dataset.cmaps[3]
+
+###############################################################################
+# demo the different 'display_mode' options
+
+plotting.plot_stat_map(localizer_cmap_filename, display_mode='ortho',
+                       cut_coords=(36, -27, 60),
+                       title="display_mode='ortho', cut_coords=(36, -27, 60)")
+
+plotting.plot_stat_map(localizer_cmap_filename, display_mode='z', cut_coords=5,
+                       title="display_mode='z', cut_coords=5")
+
+plotting.plot_stat_map(localizer_cmap_filename, display_mode='x',
+                       cut_coords=(-36, 36),
+                       title="display_mode='x', cut_coords=(-36, 36)")
+
+plotting.plot_stat_map(localizer_cmap_filename, display_mode='y', cut_coords=1,
+                       title="display_mode='x', cut_coords=(-36, 36)")
+
+plotting.plot_stat_map(localizer_cmap_filename, display_mode='z',
+                       cut_coords=1, colorbar=False,
+                       title="display_mode='z', cut_coords=1, colorbar=False")
+
+plotting.plot_stat_map(localizer_cmap_filename, display_mode='xz',
+                       cut_coords=(36, 60),
+                       title="display_mode='xz', cut_coords=(36, 60)")
+
+plotting.plot_stat_map(localizer_cmap_filename, display_mode='yx',
+                       cut_coords=(-27, 36),
+                       title="display_mode='yx', cut_coords=(-27, 36)")
+
+plotting.plot_stat_map(localizer_cmap_filename, display_mode='yz',
+                       cut_coords=(-27, 60),
+                       title="display_mode='yz', cut_coords=(-27, 60)")
+
+###############################################################################
+# demo display objects with add_ methods
+mean_haxby_img = image.mean_img(haxby_func_filename)
+
+# Plot T1 outline on top of the mean EPI (useful for checking coregistration)
+display = plotting.plot_anat(mean_haxby_img, title="add_edges")
+display.add_edges(haxby_anat_filename)
+
+# Plotting outline of the mask on top of the EPI
+display = plotting.plot_anat(mean_haxby_img, title="add_contours",
+                             cut_coords=(28, -34, -22))
+display.add_contours(haxby_mask_filename, levels=[0.5], colors='r')
+
+###############################################################################
+# demo saving plots to file
+
+plotting.plot_stat_map(localizer_cmap_filename,
+                       title='Using plot_stat_map output_file',
+                       output_file='plot_stat_map.png')
+
+display = plotting.plot_stat_map(localizer_cmap_filename,
+                                 title='Using display savefig')
+display.savefig('plot_stat_map_from_display.png')
+# In non-interactive settings make sure you close your displays
+display.close()
+
+import matplotlib.pyplot as plt
+plt.show()
diff --git a/examples/manipulating_visualizing/plot_demo_plotting.py b/examples/manipulating_visualizing/plot_demo_plotting.py
--- a/examples/manipulating_visualizing/plot_demo_plotting.py
+++ b/examples/manipulating_visualizing/plot_demo_plotting.py
@@ -1,15 +1,14 @@
 """
-Demoing Plotting functions of nilearn
-======================================
-
-Nilearn comes with a set of plotting function for Nifti-like images.
+Simple plotting in nilearn
+==========================
 
+Nilearn comes with a set of plotting function for Nifti-like images,
+see :ref:`plotting` for more details.
 """
 
 from nilearn import datasets
 from nilearn import plotting, image
 
-
 ###############################################################################
 # Retrieve the data: haxby dataset to have EPI images and masks, and
 # localizer dataset to have contrast maps
@@ -29,7 +28,14 @@
 localizer_tmap_filename = localizer_dataset.tmaps[3]
 
 ###############################################################################
-# demo the different plotting function
+# demo the different plotting functions
+
+# Plotting glass brain
+plotting.plot_glass_brain(localizer_tmap_filename, title='plot_glass_brain',
+                          threshold=3)
+
+plotting.plot_glass_brain(localizer_tmap_filename, title='plot_glass_brain',
+                          black_bg=True, display_mode='xz', threshold=3)
 
 # Plotting statistical maps
 plotting.plot_stat_map(localizer_cmap_filename, bg_img=localizer_anat_filename,
@@ -47,56 +53,5 @@
 mean_haxby_img = image.mean_img(haxby_func_filename)
 plotting.plot_epi(mean_haxby_img, title="plot_epi")
 
-# Plotting glass brain
-plotting.plot_glass_brain(localizer_tmap_filename, title='plot_glass_brain',
-                          threshold=3)
-
-plotting.plot_glass_brain(localizer_tmap_filename, title='plot_glass_brain',
-                          black_bg=True, display_mode='xz', threshold=3)
-
-###############################################################################
-# demo the different display_mode
-
-plotting.plot_stat_map(localizer_cmap_filename, display_mode='ortho',
-                       cut_coords=(36, -27, 60),
-                       title="display_mode='ortho', cut_coords=(36, -27, 60)")
-
-plotting.plot_stat_map(localizer_cmap_filename, display_mode='z', cut_coords=5,
-                       title="display_mode='z', cut_coords=5")
-
-plotting.plot_stat_map(localizer_cmap_filename, display_mode='x', cut_coords=(-36, 36),
-                       title="display_mode='x', cut_coords=(-36, 36)")
-
-plotting.plot_stat_map(localizer_cmap_filename, display_mode='y', cut_coords=1,
-                       title="display_mode='x', cut_coords=(-36, 36)")
-
-plotting.plot_stat_map(localizer_cmap_filename, display_mode='z',
-                       cut_coords=1, colorbar=False,
-                       title="display_mode='z', cut_coords=1, colorbar=False")
-
-plotting.plot_stat_map(localizer_cmap_filename, display_mode='xz',
-                       cut_coords=(36, 60),
-                       title="display_mode='xz', cut_coords=(36, 60)")
-
-plotting.plot_stat_map(localizer_cmap_filename, display_mode='yx',
-                       cut_coords=(-27, 36),
-                       title="display_mode='yx', cut_coords=(-27, 36)")
-
-plotting.plot_stat_map(localizer_cmap_filename, display_mode='yz',
-                       cut_coords=(-27, 60),
-                       title="display_mode='yz', cut_coords=(-27, 60)")
-
-###############################################################################
-# demo the outline modes
-
-# Plot T1 outline on top of the mean EPI (useful for checking coregistration)
-my_plot = plotting.plot_anat(mean_haxby_img, title="add_edges")
-my_plot.add_edges(haxby_anat_filename)
-
-# Plotting outline of the mask on top of the EPI
-my_plot = plotting.plot_anat(mean_haxby_img, title="add_contours",
-                             cut_coords=(28, -34, -22))
-my_plot.add_contours(haxby_mask_filename, levels=[0.5], colors='r')
-
-import pylab as pl
-pl.show()
+import matplotlib.pyplot as plt
+plt.show()


Test patch: