Repository: nilearn/nilearn

Issue:
Titles get ignored in plot_surf_*
<!--Provide a brief description of the bug.-->
Titles are not displayed

<!--Please fill in the following information, to the best of your ability.-->
Nilearn version:0.8.1

### Expected behavior
Title show off when provided

### Actual behavior
Title not diplsayed

### Steps and code to reproduce bug
for instance:
https://nilearn.github.io/auto_examples/01_plotting/plot_3d_map_to_surface_projection.html#sphx-glr-auto-examples-01-plotting-plot-3d-map-to-surface-projection-py


Discussion:
Indeed. I realized this yesterday working on #2902 
Since it might take some time for #2902 to get merged, I'll make a small PR to fix this in the mean time.

Resolving patch:
diff --git a/nilearn/plotting/surf_plotting.py b/nilearn/plotting/surf_plotting.py
--- a/nilearn/plotting/surf_plotting.py
+++ b/nilearn/plotting/surf_plotting.py
@@ -338,7 +338,7 @@ def plot_surf(surf_mesh, surf_map=None, bg_map=None,
         p3dcollec.set_facecolors(face_colors)
 
     if title is not None:
-        axes.set_title(title, position=(.5, .95))
+        plt.suptitle(title, x=.5, y=.95)
 
     # save figure if output file is given
     if output_file is not None:
@@ -487,10 +487,15 @@ def plot_surf_contours(surf_mesh, roi_map, axes=None, figure=None, levels=None,
         if label and legend:
             patch_list.append(Patch(color=color, label=label))
     # plot legend only if indicated and labels provided
+    pos_title_x = .5
     if legend and np.any([lbl is not None for lbl in labels]):
         figure.legend(handles=patch_list)
+        # if legends, then move title to the left
+        pos_title_x = .3
+    if title is None and hasattr(figure._suptitle, "_text"):
+        title = figure._suptitle._text
     if title:
-        figure.suptitle(title)
+        figure.suptitle(title, x=pos_title_x, y=.95)
     # save figure if output file is given
     if output_file is not None:
         figure.savefig(output_file)


Test patch:
diff --git a/nilearn/plotting/tests/test_surf_plotting.py b/nilearn/plotting/tests/test_surf_plotting.py
--- a/nilearn/plotting/tests/test_surf_plotting.py
+++ b/nilearn/plotting/tests/test_surf_plotting.py
@@ -39,6 +39,12 @@ def test_plot_surf():
     plot_surf(mesh, bg_map=bg, colorbar=True, cbar_vmin=0,
               cbar_vmax=150, cbar_tick_format="%i")
 
+    # Plot with title
+    display = plot_surf(mesh, bg_map=bg, title='Test title')
+    assert display._suptitle._text == 'Test title'
+    assert display._suptitle._x == .5
+    assert display._suptitle._y == .95
+
     # Plot with avg_method
     ## Test all built-in methods and check
     mapp = rng.standard_normal(size=mesh[0].shape[0])
@@ -165,6 +171,13 @@ def test_plot_surf_stat_map():
     plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True,
                        bg_on_data=True, darkness=0.5)
 
+    # Plot with title
+    display = plot_surf_stat_map(mesh, stat_map=data, bg_map=bg,
+                                 title="Stat map title")
+    assert display._suptitle._text == "Stat map title"
+    assert display._suptitle._x == .5
+    assert display._suptitle._y == .95
+
     # Apply threshold
     plot_surf_stat_map(mesh, stat_map=data, bg_map=bg,
                        bg_on_data=True, darkness=0.5,
@@ -471,7 +484,20 @@ def test_plot_surf_contours():
     plot_surf_contours(mesh, parcellation, figure=fig)
     fig = plot_surf(mesh)
     plot_surf_contours(mesh, parcellation, figure=fig)
-    plot_surf_contours(mesh, parcellation, title='title')
+    display = plot_surf_contours(mesh, parcellation, levels=[1, 2],
+                                 labels=['1', '2'], colors=['r', 'g'],
+                                 legend=True, title='title',
+                                 figure=fig)
+    assert display._suptitle._text == 'title'
+    assert display._suptitle._x == .3
+    assert display._suptitle._y == .95
+    fig = plot_surf(mesh, title='title 2')
+    display = plot_surf_contours(mesh, parcellation, levels=[1, 2],
+                                 labels=['1', '2'], colors=['r', 'g'],
+                                 legend=True, figure=fig)
+    assert display._suptitle._text == 'title 2'
+    assert display._suptitle._x == .3
+    assert display._suptitle._y == .95
     with tempfile.NamedTemporaryFile() as tmp_file:
         plot_surf_contours(mesh, parcellation, output_file=tmp_file.name)
     plt.close()