Skip to content

Commit

Permalink
Merge pull request matplotlib#3092 from ga7g08/fix-issue-3079
Browse files Browse the repository at this point in the history
Adds check that rgb sequence is of length 3
  • Loading branch information
tacaswell committed Jun 2, 2014
2 parents 62bae67 + dcf9a6e commit ea8fa7b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,22 @@ def to_rgba(self, arg, alpha=None):
try:
if not cbook.is_string_like(arg) and cbook.iterable(arg):
if len(arg) == 4:
if [x for x in arg if (float(x) < 0) or (x > 1)]:
# This will raise TypeError if x is not a number.
if any(float(x) < 0 or x > 1 for x in arg):
raise ValueError(
'number in rbga sequence outside 0-1 range')
if alpha is None:
return tuple(arg)
if alpha < 0.0 or alpha > 1.0:
raise ValueError("alpha must be in range 0-1")
return arg[0], arg[1], arg[2], alpha
r, g, b = arg[:3]
if [x for x in (r, g, b) if (float(x) < 0) or (x > 1)]:
if len(arg) == 3:
r, g, b = arg
if any(float(x) < 0 or x > 1 for x in arg):
raise ValueError(
'number in rbg sequence outside 0-1 range')
else:
raise ValueError(
'number in rbg sequence outside 0-1 range')
'length of rgba sequence should be either 3 or 4')
else:
r, g, b = self.to_rgb(arg)
if alpha is None:
Expand Down

0 comments on commit ea8fa7b

Please sign in to comment.