Repository: nilearn/nilearn

Issue:
'list' object cannot be interpreted for cut_coords in plot_roi
<!--Provide a brief description of the bug.-->
 Using the function 

plotting.plot_roi(atlas, view_type = "contours", bg_img=None, display_mode='z', cut_coords=[0, 20, 40, 60], annotate=False)

### Actual behavior
TypeError: 'list' object cannot be interpreted as an integer

When using  plot_stat_map  cut_coords=[0, 20, 40, 60], it works.

```python

```



Discussion:
Thx. Here is a snippet to reproduce the bug:
```
from nilearn import datasets
from nilearn import plotting
dataset_ho = datasets.fetch_atlas_harvard_oxford('cort-maxprob-thr25-2mm')
atlas = dataset_ho.filename
plotting.plot_roi(atlas, view_type = "contours", bg_img=None, display_mode='z', cut_coords=[0, 20, 40, 60], annotate=False)
```
I'm surprised we didn't run into that one before. Something like this should fix it:
```diff
diff --git a/nilearn/plotting/displays/_slicers.py b/nilearn/plotting/displays/_slicers.py
index 6c02131b7..b19704808 100644
--- a/nilearn/plotting/displays/_slicers.py
+++ b/nilearn/plotting/displays/_slicers.py
@@ -1311,7 +1311,8 @@ class BaseStackedSlicer(BaseSlicer):
         if img is None or img is False:
             bounds = ((-40, 40), (-30, 30), (-30, 75))
             lower, upper = bounds['xyz'.index(cls._direction)]
-            cut_coords = np.linspace(lower, upper, cut_coords).tolist()
+            if isinstance(cut_coords, numbers.Number):
+                cut_coords = np.linspace(lower, upper, cut_coords).tolist()
         else:
             if (not isinstance(cut_coords, collections.abc.Sequence) and
                     isinstance(cut_coords, numbers.Number)):
```

(btw note  contours without a background image will probably not be super useful -- but the bug occurs also with a background image)
"btw note contours without a background image will probably not be super useful."

I was actually using this feature in association with add_overlay =)

Anyway thanks for working on the fix
@garincle thx again for your input. Would be willing to issue a Pull Request ?
I would, but I have no idea how to do that correctly. If someone walk me through I would be happy to learn.
Does the following help ?
https://github.com/nilearn/nilearn/blob/main/CONTRIBUTING.rst
If you feel it's too hard, simply let us know, somebody will take that one.
Best,
yeah, this is not a good time for me to dive into that (but I need to do it!). I will try to learn a bit more before I can contribute if that's ok?
Sure. 

Resolving patch:
diff --git a/nilearn/plotting/displays/_slicers.py b/nilearn/plotting/displays/_slicers.py
--- a/nilearn/plotting/displays/_slicers.py
+++ b/nilearn/plotting/displays/_slicers.py
@@ -1311,7 +1311,8 @@ def find_cut_coords(cls, img=None, threshold=None, cut_coords=None):
         if img is None or img is False:
             bounds = ((-40, 40), (-30, 30), (-30, 75))
             lower, upper = bounds['xyz'.index(cls._direction)]
-            cut_coords = np.linspace(lower, upper, cut_coords).tolist()
+            if isinstance(cut_coords, numbers.Number):
+                cut_coords = np.linspace(lower, upper, cut_coords).tolist()
         else:
             if (not isinstance(cut_coords, collections.abc.Sequence) and
                     isinstance(cut_coords, numbers.Number)):


Test patch:
diff --git a/nilearn/plotting/tests/test_img_plotting/test_plot_roi.py b/nilearn/plotting/tests/test_img_plotting/test_plot_roi.py
--- a/nilearn/plotting/tests/test_img_plotting/test_plot_roi.py
+++ b/nilearn/plotting/tests/test_img_plotting/test_plot_roi.py
@@ -26,7 +26,10 @@ def demo_plot_roi(**kwargs):
 @pytest.mark.parametrize('black_bg', [True, False])
 @pytest.mark.parametrize('threshold', [.5, .2])
 @pytest.mark.parametrize('alpha', [.7, .1])
-def test_plot_roi_view_types(view_type, black_bg, threshold, alpha):
+@pytest.mark.parametrize('display_mode,cut_coords', [("ortho", None), ("z", 3),
+                                                     ("x", [2., 10])])
+def test_plot_roi_view_types(view_type, black_bg, threshold, alpha,
+                             display_mode, cut_coords):
     """Smoke-test for plot_roi.
 
     Tests different combinations of parameters `view_type`, `black_bg`,
@@ -35,8 +38,13 @@ def test_plot_roi_view_types(view_type, black_bg, threshold, alpha):
     kwargs = dict()
     if view_type == 'contours':
         kwargs["linewidth"] = 2.
-    demo_plot_roi(view_type=view_type, black_bg=black_bg, threshold=threshold,
-                  alpha=alpha, **kwargs)
+    demo_plot_roi(view_type=view_type,
+                  black_bg=black_bg,
+                  threshold=threshold,
+                  alpha=alpha,
+                  display_mode=display_mode,
+                  cut_coords=cut_coords,
+                  **kwargs)
     plt.close()