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

Skip to content

Commit 977d718

Browse files
GregoryAshtontobias47n9e
authored andcommitted
Adds check that rgb sequence is of length 3
1 parent 33346c7 commit 977d718

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/matplotlib/colors.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,14 @@ def to_rgba(self, arg, alpha=None):
358358
if alpha < 0.0 or alpha > 1.0:
359359
raise ValueError("alpha must be in range 0-1")
360360
return arg[0], arg[1], arg[2], alpha
361-
r, g, b = arg[:3]
362-
if [x for x in (r, g, b) if (float(x) < 0) or (x > 1)]:
361+
if len(arg) == 3:
362+
r, g, b = arg
363+
if [x for x in (r, g, b) if (float(x) < 0) or (x > 1)]:
364+
raise ValueError(
365+
'number in rbg sequence outside 0-1 range')
366+
else:
363367
raise ValueError(
364-
'number in rbg sequence outside 0-1 range')
368+
'length of rgba sequence should be either 3 or 4')
365369
else:
366370
r, g, b = self.to_rgb(arg)
367371
if alpha is None:

0 commit comments

Comments
 (0)