Repository: nilearn/nilearn

Issue:
[BUG] NiftiSpheresMasker reports do not show sphere where there is only one
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Operating system

- [X] Linux
- [ ] Mac
- [ ] Windows

### Operating system version

For example one of the following:
- Linux Ubuntu 22.04



### Python version

- [ ] 3.12
- [X] 3.11
- [ ] 3.10
- [ ] 3.9
- [ ] 3.8

### nilearn version

Dev version

### Expected behavior

The NiftiSpheresMasker to show me one sphere

### Current behavior & error messages

This is what I got:

![image](https://github.com/nilearn/nilearn/assets/6961185/029a7377-40a7-4324-9ba8-1f239b0c0026)


Where as with 2 spheres

![image](https://github.com/nilearn/nilearn/assets/6961185/747cf742-9c10-4d8b-bfb1-6300567ed8af)



### Steps and code to reproduce bug

```python
from nilearn.maskers import NiftiSpheresMasker

from nilearn import datasets

adhd_dataset = datasets.fetch_adhd(n_subjects=1)

coords = [(0, -52, 18), (-46, -68, 32)]

masker_1 = NiftiSpheresMasker(
    [coords[0]],
    radius=8,
    detrend=True,
    standardize=True,
    low_pass=0.1,
    high_pass=0.01,
    t_r=2.0,
    memory="nilearn_cache",
    memory_level=1,
)

masker_2 = NiftiSpheresMasker(
    coords,
    radius=8,
    detrend=True,
    standardize=True,
    low_pass=0.1,
    high_pass=0.01,
    t_r=2.0,
    memory="nilearn_cache",
    memory_level=1,
)

_ = masker_1.fit_transform(adhd_dataset.func[0])
report = masker_1.generate_report()
report.save_as_html("report1.html")

_ = masker_2.fit_transform(adhd_dataset.func[0])
report = masker_2.generate_report()
report.save_as_html("report2.html")
```



Discussion:

Resolving patch:
diff --git a/nilearn/maskers/nifti_spheres_masker.py b/nilearn/maskers/nifti_spheres_masker.py
--- a/nilearn/maskers/nifti_spheres_masker.py
+++ b/nilearn/maskers/nifti_spheres_masker.py
@@ -333,13 +333,13 @@ def __init__(
         # Parameters for reporting
         self.reports = reports
         self.report_id = -1
-        self._report_content = dict()
-        self._report_content["description"] = (
-            "This reports shows the regions "
-            "defined by the spheres of the masker."
-        )
-        self._report_content["warning_message"] = None
-
+        self._report_content = {
+            "description": (
+                "This reports shows the regions defined "
+                "by the spheres of the masker."
+            ),
+            "warning_message": None,
+        }
         self.verbose = verbose
 
     def generate_report(self, displayed_spheres="all"):
@@ -506,7 +506,9 @@ def _reporting(self):
             )
             regions_summary["relative size (in %)"].append("not implemented")
             if idx in spheres_to_be_displayed:
-                display = plotting.plot_img(img, cut_coords=positions[idx])
+                display = plotting.plot_img(
+                    img, cut_coords=positions[idx], cmap="gray"
+                )
                 display.add_markers(
                     marker_coords=[positions[idx]],
                     marker_color="g",
diff --git a/nilearn/reporting/html_report.py b/nilearn/reporting/html_report.py
--- a/nilearn/reporting/html_report.py
+++ b/nilearn/reporting/html_report.py
@@ -7,6 +7,7 @@
 from string import Template
 
 from nilearn.externals import tempita
+from nilearn.maskers import NiftiSpheresMasker
 from nilearn.plotting.html_document import HTMLDocument
 from nilearn.reporting.utils import figure_to_svg_base64
 
@@ -163,6 +164,9 @@ def _define_overlay(estimator):
     if len(displays) == 1:  # set overlay to None
         overlay, image = None, displays[0]
 
+    elif isinstance(estimator, NiftiSpheresMasker):
+        overlay, image = None, displays
+
     elif len(displays) == 2:
         overlay, image = displays[0], displays[1]
 


Test patch:
diff --git a/nilearn/reporting/tests/test_html_report.py b/nilearn/reporting/tests/test_html_report.py
--- a/nilearn/reporting/tests/test_html_report.py
+++ b/nilearn/reporting/tests/test_html_report.py
@@ -323,6 +323,21 @@ def test_nifti_spheres_masker_report_displayed_spheres_list_more_than_seeds():
         masker.generate_report(displayed_spheres=displayed_spheres)
 
 
+def test_nifti_spheres_masker_report_1_sphere():
+    """Check the report for sphere actually works for one sphere.
+
+    See https://github.com/nilearn/nilearn/issues/4268
+    """
+    report = NiftiSpheresMasker([(1, 1, 1)]).fit().generate_report()
+
+    empty_div = """
+                    <img id="map1" class="pure-img" width="100%"
+                        src="data:image/svg+xml;base64,D"
+                        style="display:none;" alt="image"/>"""
+
+    assert empty_div not in report.body
+
+
 def test_nifti_labels_masker_report_smoke_test(labels, labels_img):
     """Smoke test."""
     labels_img_floats = new_img_like(