Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c163a0

Browse files
GregoryAshtontobias47n9e
authored andcommitted
Improves check of arg range
1 parent 977d718 commit 5c163a0

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/matplotlib/colors.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ def to_rgba(self, arg, alpha=None):
349349
try:
350350
if not cbook.is_string_like(arg) and cbook.iterable(arg):
351351
if len(arg) == 4:
352-
if [x for x in arg if (float(x) < 0) or (x > 1)]:
353-
# This will raise TypeError if x is not a number.
352+
if any(float(x) < 0. or float(x) > 1. for x in arg):
354353
raise ValueError(
355354
'number in rbga sequence outside 0-1 range')
356355
if alpha is None:
@@ -360,7 +359,7 @@ def to_rgba(self, arg, alpha=None):
360359
return arg[0], arg[1], arg[2], alpha
361360
if len(arg) == 3:
362361
r, g, b = arg
363-
if [x for x in (r, g, b) if (float(x) < 0) or (x > 1)]:
362+
if any(float(x) < 0. or float(x) > 1. for x in arg):
364363
raise ValueError(
365364
'number in rbg sequence outside 0-1 range')
366365
else:

0 commit comments

Comments
 (0)