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

Skip to content

Commit 879c8b9

Browse files
committed
Fix bug specifying alpha in a color array. (Thanks, Mátyás János)
svn path=/trunk/matplotlib/; revision=5554
1 parent 87c3b37 commit 879c8b9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

lib/matplotlib/colors.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,15 @@ def to_rgba(self, arg, alpha=None):
291291
"""
292292
try:
293293
if not cbook.is_string_like(arg) and cbook.iterable(arg):
294-
if len(arg) == 4 and alpha is None:
294+
if len(arg) == 4:
295295
if [x for x in arg if (float(x) < 0) or (x > 1)]:
296296
# This will raise TypeError if x is not a number.
297297
raise ValueError('number in rbga sequence outside 0-1 range')
298-
return tuple(arg)
298+
if alpha is None:
299+
return tuple(arg)
300+
if alpha < 0.0 or alpha > 1.0:
301+
raise ValueError("alpha must be in range 0-1")
302+
return arg[0], arg[1], arg[2], arg[3] * alpha
299303
r,g,b = arg[:3]
300304
if [x for x in (r,g,b) if (float(x) < 0) or (x > 1)]:
301305
raise ValueError('number in rbg sequence outside 0-1 range')

0 commit comments

Comments
 (0)