Repository: nilearn/nilearn

Issue:
plotting.view_markers marker_labels
I have been using `plotting.view_markers` for some time and really like the ability to define marker_color. I am wondering if it's possible to add marker_label as well?

### Benefits to the change
I think many users would find this helpful, especially when plotting many points at one time. In our use case, we are displaying depth electrode contacts for epilepsy patients and having each contact point labelled would be a benefit to our clinicians.

```python
import matplotlib.pyplot as plt
from nilearn import plotting

labels = #string label for each electrode contact
groups = #of implanted electrodes
n_members = #of contacts for each electrode

cmap = plt.get_cmap('rainbow')
colors=np.repeat(cmap(np.linspace(0, 1, len(groups))), n_members, axis=0)

html_view = plotting.view_markers(coordinates, marker_size=5.0, marker_color=colors, marker_labels=labels)
```



Discussion:
Thx ! Sounds like a good idea. Are you interested in working on it ?
Best,
Bertrand
yes, can do. Any advice on where I should start? 
Hi @greydongilmore 

Indeed, this would be nice to have! :+1: 
I had a quick look, and it seems we will need to do the following things:

- Update function `view_markers` to support a `marker_labels` argument (basic checks, and then add it to the `connectome_info` dictionary):

https://github.com/nilearn/nilearn/blob/dc9c21a7bec637f0aaad650372bbf4e59b294dec/nilearn/plotting/html_connectome.py#L180-L181

- Update `nilearn/plotting/data/html/connectome_plot_template.html`: use the passed labels to add a `text` field to the Plotly figure (see examples in doc [here](https://plotly.com/javascript/line-and-scatter/)).

https://github.com/nilearn/nilearn/blob/dc9c21a7bec637f0aaad650372bbf4e59b294dec/nilearn/plotting/data/html/connectome_plot_template.html#L129-L140

Does this make sense?
yes, makes sense to me! I will get working on it :+1: 

Resolving patch:
diff --git a/nilearn/plotting/html_connectome.py b/nilearn/plotting/html_connectome.py
--- a/nilearn/plotting/html_connectome.py
+++ b/nilearn/plotting/html_connectome.py
@@ -178,7 +178,7 @@ def view_connectome(adjacency_matrix, node_coords, edge_threshold=None,
 
 
 def view_markers(marker_coords, marker_color=None, marker_size=5.,
-                 title=None, title_fontsize=25):
+                 marker_labels=None, title=None, title_fontsize=25):
     """Insert a 3d plot of markers in a brain into an HTML page.
 
     Parameters
@@ -194,6 +194,9 @@ def view_markers(marker_coords, marker_color=None, marker_size=5.,
     marker_size : float or array-like, optional
         Size of the markers showing the seeds in pixels. Default=5.0.
 
+    marker_labels : list of str, shape=(n_nodes), optional
+        Labels for the markers: list of strings
+
     title : str, optional
         Title for the plot.
 
@@ -228,7 +231,10 @@ def view_markers(marker_coords, marker_color=None, marker_size=5.,
     connectome_info = _get_markers(marker_coords, marker_color)
     if hasattr(marker_size, 'tolist'):
         marker_size = marker_size.tolist()
+    if marker_labels is None:
+        marker_labels = ['' for i in range(marker_coords.shape[0])]
     connectome_info["marker_size"] = marker_size
+    connectome_info["marker_labels"] = marker_labels
     connectome_info['title'] = title
     connectome_info['title_fontsize'] = title_fontsize
     return _make_connectome_html(connectome_info)


Test patch:
diff --git a/nilearn/plotting/tests/test_html_connectome.py b/nilearn/plotting/tests/test_html_connectome.py
--- a/nilearn/plotting/tests/test_html_connectome.py
+++ b/nilearn/plotting/tests/test_html_connectome.py
@@ -1,4 +1,5 @@
 import warnings
+import json
 
 import numpy as np
 
@@ -84,6 +85,8 @@ def test_get_markers():
 def test_view_markers():
     coords = np.arange(12).reshape((4, 3))
     colors = ['r', 'g', 'black', 'white']
+    labels = ["red marker", "green marker", 
+          "black marker", "white marker"]
     html = html_connectome.view_markers(coords, colors)
     check_html(html, False, 'connectome-plot')
     html = html_connectome.view_markers(coords)
@@ -96,4 +99,10 @@ def test_view_markers():
     html = html_connectome.view_markers(
         coords, marker_size=list(range(len(coords))))
     check_html(html, False, 'connectome-plot')
+    html = html_connectome.view_markers(coords, 
+                                    marker_size=5.0,
+                                    marker_color=colors,
+                                    marker_labels=labels)
+    labels_dict = {"marker_labels": labels}
+    assert json.dumps(labels_dict)[1:-1] in html.html