Repository: nilearn/nilearn

Issue:
nilearn.plotting.plot_connectome does not support node_color in array format
- What version of Nilearn are you using?
Tested in both v0.5.2 and v0.6.0 (with help from @jeromedockes). 
- What were you trying to do?
I would like to specify a list of colors for nodes for plot_connectome.
- What did you expect will happen?
The current version only supports node_color in list format, but not array format. 
- What actually happened?
Errors were reported like below (v0.5.2). 
```
ValueError                                Traceback (most recent call last)
<ipython-input-23-1935b6c630f1> in <module>()
----> 1 plotting.plot_connectome(connetome, coords, node_color=np.array(['red','seagreen','blue']))

/home/xiakon/.conda/envs/bigpype/lib/python2.7/site-packages/nilearn/plotting/img_plotting.pyc in plot_connectome(adjacency_matrix, node_coords, node_color, node_size, edge_cmap, edge_vmin, edge_vmax, edge_threshold, output_file, display_mode, figure, axes, title, annotate, black_bg, alpha, edge_kwargs, node_kwargs, colorbar)
   1283                       edge_threshold=edge_threshold,
   1284                       edge_kwargs=edge_kwargs, node_kwargs=node_kwargs,
-> 1285                       colorbar=colorbar)
   1286 
   1287     if output_file is not None:

/home/xiakon/.conda/envs/bigpype/lib/python2.7/site-packages/nilearn/plotting/displays.pyc in add_graph(self, adjacency_matrix, node_coords, node_color, node_size, edge_cmap, edge_vmin, edge_vmax, edge_threshold, edge_kwargs, node_kwargs, colorbar)
   1750         if node_kwargs is None:
   1751             node_kwargs = {}
-> 1752         if node_color == 'auto':
   1753             nb_nodes = len(node_coords)
   1754             node_color = mpl_cm.Set2(np.linspace(0, 1, nb_nodes))

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```

Here is the code for quick reproducing the problem. 
```
from nilearn import plotting
import numpy as np
coords = [(0,-52,18),(-46,-68,32),(46,-68,32)]
connetome = np.ones((3,3))
plotting.plot_connectome(connetome, coords, node_color=np.array(['red','seagreen','blue']))
```
I used np.array here just for simulating the situation when we specifying node_color via a column of a csv file. 





Discussion:

Resolving patch:
diff --git a/nilearn/plotting/displays.py b/nilearn/plotting/displays.py
--- a/nilearn/plotting/displays.py
+++ b/nilearn/plotting/displays.py
@@ -1776,10 +1776,9 @@ def add_graph(self, adjacency_matrix, node_coords,
             edge_kwargs = {}
         if node_kwargs is None:
             node_kwargs = {}
-        if node_color == 'auto':
+        if isinstance(node_color, str) and node_color == 'auto':
             nb_nodes = len(node_coords)
             node_color = mpl_cm.Set2(np.linspace(0, 1, nb_nodes))
-
         node_coords = np.asarray(node_coords)
 
         # decompress input matrix if sparse
@@ -1815,6 +1814,13 @@ def add_graph(self, adjacency_matrix, node_coords,
 
             raise ValueError(message)
 
+        if isinstance(node_color, (list, np.ndarray)) and len(node_color) != 1:
+            if len(node_color) != node_coords_shape[0]:
+                raise ValueError(
+                    "Mismatch between the number of nodes ({0}) "
+                    "and and the number of node colors ({1})."
+                    .format(node_coords_shape[0], len(node_color)))
+
         if node_coords_shape[0] != adjacency_matrix_shape[0]:
             raise ValueError(
                 "Shape mismatch between 'adjacency_matrix' "


Test patch:
diff --git a/nilearn/plotting/tests/test_img_plotting.py b/nilearn/plotting/tests/test_img_plotting.py
--- a/nilearn/plotting/tests/test_img_plotting.py
+++ b/nilearn/plotting/tests/test_img_plotting.py
@@ -478,6 +478,22 @@ def test_plot_connectome(tmpdir):
     plot_connectome(*args, **kwargs)
     plt.close()
 
+    # Unique node color
+    node_color = np.array(['red'])
+    kwargs = dict(edge_threshold=0.38,
+                  title='threshold=0.38',
+                  node_size=10, node_color=node_color)
+    plot_connectome(*args, **kwargs)
+    plt.close()
+
+    node_color = 'green'
+    kwargs = dict(edge_threshold=0.38,
+                  title='threshold=0.38',
+                  node_size=10)
+    plot_connectome(*args, node_color=node_color, **kwargs)
+    plt.close()
+
+
     # used to speed-up tests for the next plots
     kwargs['display_mode'] = 'x'
 
@@ -520,7 +536,8 @@ def test_plot_connectome(tmpdir):
     plt.close()
 
     # NaN matrix support
-    node_color = ['green', 'blue', 'k']
+    # Node colors specified as a numpy array rather than a list
+    node_color = np.array(['green', 'blue', 'k'])
     # Overriding 'node_color' for 3  elements of size 3.
     kwargs['node_color'] = node_color
     nan_adjacency_matrix = np.array([[1., np.nan, 0.],
@@ -579,6 +596,19 @@ def test_plot_connectome_exceptions():
                         edge_threshold=object(),
                         **kwargs)
 
+    # wrong number of node colors
+    with pytest.raises(ValueError,
+                       match='Mismatch between the number of nodes'):
+        plot_connectome(adjacency_matrix, node_coords,
+                        node_color=['red', 'blue', 'yellow'],
+                        **kwargs)
+
+    with pytest.raises(ValueError,
+                       match='Mismatch between the number of nodes'):
+        plot_connectome(adjacency_matrix, node_coords,
+                        node_color=np.array(['red', 'blue', 'yellow', 'cyan']),
+                        **kwargs)
+
     # wrong shapes for node_coords or adjacency_matrix
     with pytest.raises(
             ValueError,