Repository: graspologic-org/graspologic

Issue:
[BUG] `Networkplot` assumes `node_data` is integer 0...n-1 indexed
## Expected Behavior
`Networkplot` should work with arbitrarily indexed `node_data`

## Actual Behavior
Obscure error with matplotlib caused by incorrect series mapping for colors

## What's going on 
If you look at this line 
https://github.com/microsoft/graspologic/blob/96d80b2261cff724bf0a082a249e60ee8ec1a878/graspologic/plot/plot.py#L1366

it is doing a map operation using `plot_df[hue_key]` as the mapping. This is a `pd.Series`, so the mapping is `plot_df.index` -> elements of the series `plot_df[hue_key]`. However, I passed in data where the index of the node data were names of neurons as opposed to an integer index that goes 0...n-1. This is implicitly what is being assumed here since at this point in the code, nodes in `edgelist` are indexed numerically.

## What to do
I think this can basically be resolved by doing `plot_df = plot_df.reset_index()`, which assumes that `plot_df` and `adjacency` are positionally indexed, but we assume that already. also should add a test for this use case. 

cc @dlee0156 


Discussion:

Resolving patch:
diff --git a/graspologic/plot/plot.py b/graspologic/plot/plot.py
--- a/graspologic/plot/plot.py
+++ b/graspologic/plot/plot.py
@@ -1319,6 +1319,7 @@ def networkplot(
                 "If x and y are strings, node_data must be pandas DataFrame."
             )
         plot_df = node_data.copy()
+        plot_df = plot_df.reset_index(drop=True)
         x_key = x
         y_key = y
         if node_hue is not None:


Test patch:
diff --git a/tests/test_plot.py b/tests/test_plot.py
--- a/tests/test_plot.py
+++ b/tests/test_plot.py
@@ -280,7 +280,7 @@ def test_pairplot_with_gmm_outputs_type_spherical(self):
         _test_pairplot_with_gmm_outputs(covariance_type="spherical")
 
     def test_networkplot_inputs(self):
-        X = np.random.rand(15, 3)
+        X = er_np(15, 0.5)
         x = np.random.rand(15, 1)
         y = np.random.rand(15, 1)
         with self.assertRaises(beartype.roar.BeartypeCallHintPepParamException):
@@ -328,8 +328,8 @@ def test_networkplot_inputs(self):
             with self.assertRaises(TypeError):
                 networkplot(adjacency=X, x=x, y=y, legend=4)
 
-    def test_networkplot_outputs(self):
-        X = np.random.rand(15, 3)
+    def test_networkplot_outputs_int(self):
+        X = er_np(15, 0.5)
         xarray = np.random.rand(15, 1)
         yarray = np.random.rand(15, 1)
         xstring = "source"
@@ -364,6 +364,30 @@ def test_networkplot_outputs(self):
             ax=ax,
         )
 
+    def test_networkplot_outputs_str(self):
+        X = er_np(15, 0.7)
+        node_df = pd.DataFrame(index=["node {}".format(i) for i in range(15)])
+        node_df.loc[:, "source"] = np.random.rand(15, 1)
+        node_df.loc[:, "target"] = np.random.rand(15, 1)
+        node_df.loc[:, "hue"] = np.random.randint(2, size=15)
+        palette = {0: (0.8, 0.4, 0.2), 1: (0, 0.9, 0.4)}
+        size = np.random.rand(15)
+        sizes = (10, 200)
+
+        fig = networkplot(
+            adjacency=X,
+            x="source",
+            y="target",
+            node_data=node_df,
+            node_hue="hue",
+            palette=palette,
+            node_size=size,
+            node_sizes=sizes,
+            node_alpha=0.5,
+            edge_alpha=0.4,
+            edge_linewidth=0.6,
+        )
+
     def test_sort_inds(self):
         B = np.array(
             [