Skip to content

Commit 72bf994

Browse files
committed
FIX 2-tuple of colors in to_rgba_array
1 parent e3a5cee commit 72bf994

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/matplotlib/colors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def to_rgba_array(c, alpha=None):
435435
(n, 4) array of RGBA colors, where each channel (red, green, blue,
436436
alpha) can assume values between 0 and 1.
437437
"""
438-
if isinstance(c, tuple) and len(c) == 2:
438+
if isinstance(c, tuple) and len(c) == 2 and isinstance(c[1], Real):
439439
if alpha is None:
440440
c, alpha = c
441441
else:

lib/matplotlib/tests/test_colors.py

+5
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,11 @@ def test_to_rgba_array_single_str():
12981298
array = mcolors.to_rgba_array("rgb")
12991299

13001300

1301+
def test_to_rgba_array_2tuple_str():
1302+
expected = np.array([[0, 0, 0, 1], [1, 1, 1, 1]])
1303+
assert_array_equal(mcolors.to_rgba_array(("k", "w")), expected)
1304+
1305+
13011306
def test_to_rgba_array_alpha_array():
13021307
with pytest.raises(ValueError, match="The number of colors must match"):
13031308
mcolors.to_rgba_array(np.ones((5, 3), float), alpha=np.ones((2,)))

0 commit comments

Comments
 (0)