Repository: xgi-org/xgi

Issue:
Warning when specifying node colors
A minimal working example is
```python
import xgi
import random

H = xgi.Hypergraph([[1, 2], [2, 3, 4]])

c1 = "maroon"
c2 = "white"
node_fc = [c1 if random.random() < 0.5 else c2 for i in H.nodes]
xgi.draw(H, node_fc=node_fc)
```
produces this warning
```
UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  node_collection = ax.scatter(
```

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/xgi-org/xgi/pull/512?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`1e746bf`)](https://app.codecov.io/gh/xgi-org/xgi/commit/1e746bfef6056112b785a72f55d826c50fd165de?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org) 92.03% compared to head [(`7d3b5aa`)](https://app.codecov.io/gh/xgi-org/xgi/pull/512?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org) 92.01%.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #512      +/-   ##
==========================================
- Coverage   92.03%   92.01%   -0.03%     
==========================================
  Files          60       60              
  Lines        4369     4370       +1     
==========================================
  Hits         4021     4021              
- Misses        348      349       +1     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/xgi-org/xgi/pull/512?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xgi-org).

maximelucas: Thanks! Could you maybe just add a test to make sure there is no warning?
nwlandry: > Thanks! Could you maybe just add a test to make sure there is no warning?

Done!
maximelucas: Perfect thanks!

Patch:
diff --git a/xgi/drawing/draw.py b/xgi/drawing/draw.py
index 37032ea..09dfe5d 100644
--- a/xgi/drawing/draw.py
+++ b/xgi/drawing/draw.py
@@ -7,6 +7,7 @@ import matplotlib.pyplot as plt
 import numpy as np
 import seaborn as sb  # for cmap "crest"
 from matplotlib import cm
+from matplotlib.colors import is_color_like
 from matplotlib.patches import FancyArrowPatch
 from mpl_toolkits.mplot3d.art3d import (
     Line3DCollection,
@@ -433,10 +434,6 @@ def draw_nodes(
     settings.update(params)
     settings.update(kwargs)
 
-    # avoid matplotlib scatter UserWarning "Parameters 'cmap' will be ignored"
-    if isinstance(node_fc, str):
-        node_fc_cmap = None
-
     ax, pos = _draw_init(H, ax, pos)
 
     # convert pos to format convenient for scatter
@@ -450,6 +447,12 @@ def draw_nodes(
     node_fc = _draw_arg_to_arr(node_fc)
     node_lw = _draw_arg_to_arr(node_lw)
 
+    # avoid matplotlib scatter UserWarning "Parameters 'cmap' will be ignored"
+    if isinstance(node_fc, str) or (
+        isinstance(node_fc, np.ndarray) and is_color_like(node_fc[0])
+    ):
+        node_fc_cmap = None
+
     # check validity of input values
     if np.any(node_size < 0):
         raise ValueError("node_size cannot contain negative values.")


Test patch:
diff --git a/tests/drawing/test_draw.py b/tests/drawing/test_draw.py
index 4fef015..c31d8e0 100644
--- a/tests/drawing/test_draw.py
+++ b/tests/drawing/test_draw.py
@@ -1,3 +1,5 @@
+import warnings
+
 import matplotlib.pyplot as plt
 import numpy as np
 import pytest
@@ -514,7 +516,7 @@ def test_draw_multilayer(edgelist8):
     # node_size
     assert np.all(node_coll4.get_sizes() == np.array([10**2]))
 
-    plt.close()
+    plt.close("all")
 
 
 def test_draw_dihypergraph(diedgelist2, edgelist8):
@@ -587,8 +589,6 @@ def test_draw_dihypergraph(diedgelist2, edgelist8):
     for patch in ax1.patches:  # lines
         assert patch.get_zorder() == 0
 
-    plt.close("all")
-
     # test toggle for edges
     fig, ax2 = plt.subplots()
     ax2, collections = xgi.draw_dihypergraph(DH, edge_marker_toggle=False, ax=ax2)
@@ -596,7 +596,7 @@ def test_draw_dihypergraph(diedgelist2, edgelist8):
     assert len(ax2.collections) == 1
     assert phantom_node_coll is None
 
-    plt.close()
+    plt.close("all")
 
     # test XGI ERROR raise
     with pytest.raises(XGIError):
@@ -622,3 +622,20 @@ def test_draw_dihypergraph_with_str_labels_and_isolated_nodes():
     assert len(node_coll4.get_offsets()) == 6  # number of original nodes
     assert len(phantom_node_coll4.get_offsets()) == 2  # number of original edges
     assert len(ax4.patches) == 7  # number of lines
+    plt.close()
+
+
+def test_issue_499(edgelist8):
+    H = xgi.Hypergraph(edgelist8)
+
+    fig, ax = plt.subplots()
+
+    with warnings.catch_warnings():
+        warnings.simplefilter("error")
+        ax, collections = xgi.draw(H, ax=ax, node_fc="black")
+
+    with warnings.catch_warnings():
+        warnings.simplefilter("error")
+        ax, collections = xgi.draw(H, ax=ax, node_fc=["black"] * H.num_nodes)
+
+    plt.close("all")