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

Skip to content

Commit bda202b

Browse files
committed
MNT: always validate alpha as [0, 1] or None
1 parent e049a49 commit bda202b

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/matplotlib/colors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ def to_rgba(self, arg, alpha=None):
203203
except AttributeError:
204204
pass
205205

206+
if alpha is not None and (alpha < 0.0 or alpha > 1.0):
207+
raise ValueError("alpha must be in range 0-1")
208+
206209
try:
207210
if not cbook.is_string_like(arg) and cbook.iterable(arg):
208211
if len(arg) == 4:
@@ -211,8 +214,6 @@ def to_rgba(self, arg, alpha=None):
211214
'number in rbga sequence outside 0-1 range')
212215
if alpha is None:
213216
return tuple(arg)
214-
if alpha < 0.0 or alpha > 1.0:
215-
raise ValueError("alpha must be in range 0-1")
216217
return arg[0], arg[1], arg[2], alpha
217218
if len(arg) == 3:
218219
r, g, b = arg

0 commit comments

Comments
 (0)