Repository: nilearn/nilearn

Issue:
[ENH] Adjust the image output size of plotting.view_img()
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe your proposed enhancement in detail.

I would like to add an input to view_img() to control the size of the output HTML image.

### Benefits to the change

The output image from view_img() is sometimes too small for exploring activation maps in detail.

### Pseudocode for the new behavior, if applicable

```python
from nilearn.plotting import view_img

view_img(<path_to_img>, width_view = 1000)

```



Discussion:

Resolving patch:
diff --git a/nilearn/plotting/html_stat_map.py b/nilearn/plotting/html_stat_map.py
--- a/nilearn/plotting/html_stat_map.py
+++ b/nilearn/plotting/html_stat_map.py
@@ -317,7 +317,7 @@ def _json_view_params(
     return params
 
 
-def _json_view_size(params):
+def _json_view_size(params, width_view=600):
     """Define the size of the viewer.
 
     Returns: width_view, height_view
@@ -333,7 +333,6 @@ def _json_view_size(params):
     slices_height = 1.20 * slices_height
 
     # Get the final size of the viewer
-    width_view = 600
     ratio = slices_height / slices_width
     height_view = np.ceil(ratio * width_view)
 
@@ -412,14 +411,14 @@ def _json_view_data(
     return json_view
 
 
-def _json_view_to_html(json_view):
+def _json_view_to_html(json_view, width_view=600):
     """Fill a brainsprite html template with relevant parameters and data.
 
     Returns: html_view
 
     """
     # Fix the size of the viewer
-    width, height = _json_view_size(json_view["params"])
+    width, height = _json_view_size(json_view["params"], width_view)
 
     # Populate all missing keys with html-ready data
     json_view["INSERT_PAGE_TITLE_HERE"] = (
@@ -489,6 +488,7 @@ def view_img(
     vmax=None,
     vmin=None,
     resampling_interpolation="continuous",
+    width_view=600,
     opacity=1,
 ):
     """Interactive html viewer of a statistical map, with optional background.
@@ -553,6 +553,11 @@ def view_img(
         image, or 0 when a threshold is used.
     %(resampling_interpolation)s
         Default='continuous'.
+
+    width_view : int, optional
+        Default=600.
+        Width of the viewer in pixels.
+
     opacity : float in [0,1], default=1
         The level of opacity of the overlay (0: transparent, 1: opaque).
 
@@ -627,6 +632,6 @@ def view_img(
         value=False,
     )
 
-    html_view = _json_view_to_html(json_view)
+    html_view = _json_view_to_html(json_view, width_view)
 
     return html_view


Test patch:
diff --git a/nilearn/plotting/tests/test_html_stat_map.py b/nilearn/plotting/tests/test_html_stat_map.py
--- a/nilearn/plotting/tests/test_html_stat_map.py
+++ b/nilearn/plotting/tests/test_html_stat_map.py
@@ -10,8 +10,7 @@
 from nilearn import datasets, image
 from nilearn.image import get_data, new_img_like
 from nilearn.plotting import html_stat_map
-
-from ..js_plotting_utils import colorscale
+from nilearn.plotting.js_plotting_utils import colorscale
 
 
 def _check_html(html_view, title=None):
@@ -380,6 +379,8 @@ def test_view_img():
         _check_html(html_view)
         html_view = html_stat_map.view_img(img_4d, threshold=1e6)
         _check_html(html_view)
+        html_view = html_stat_map.view_img(img_4d, width_view=1000)
+        _check_html(html_view)
 
     # Check that all warnings were expected
     warnings_set = {warning_.category for warning_ in w}