Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd35a7d8

Browse files
committed
FIX 2-tuple of colors in to_rgba_array
1 parente3a5cee commitd35a7d8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
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-
ifisinstance(c,tuple)andlen(c)==2:
438+
ifisinstance(c,tuple)andlen(c)==2andisinstance(c[1], (int,float)):
439439
ifalphaisNone:
440440
c,alpha=c
441441
else:

‎lib/matplotlib/tests/test_colors.py

Lines changed: 5 additions & 0 deletions
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+
deftest_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
deftest_to_rgba_array_alpha_array():
13021307
withpytest.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)

[8]ページ先頭

©2009-2025 Movatter.jp