Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def to_rgba_array(c, alpha=None):
(n, 4) array of RGBA colors, where each channel (red, green, blue,
alpha) can assume values between 0 and 1.
"""
if isinstance(c, tuple) and len(c) == 2:
if isinstance(c, tuple) and len(c) == 2 and isinstance(c[1], Real):
if alpha is None:
c, alpha = c
else:
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,11 @@ def test_to_rgba_array_single_str():
array = mcolors.to_rgba_array("rgb")


def test_to_rgba_array_2tuple_str():
expected = np.array([[0, 0, 0, 1], [1, 1, 1, 1]])
assert_array_equal(mcolors.to_rgba_array(("k", "w")), expected)


def test_to_rgba_array_alpha_array():
with pytest.raises(ValueError, match="The number of colors must match"):
mcolors.to_rgba_array(np.ones((5, 3), float), alpha=np.ones((2,)))
Expand Down