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

Skip to content

Commit 2a1c6a5

Browse files
committed
Reduced overhead in to_rgba(arg) if arg is already an rgb or rgba.
svn path=/trunk/matplotlib/; revision=2739
1 parent 685ed0c commit 2a1c6a5

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

lib/matplotlib/colors.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,19 @@ def to_rgba(self, arg, alpha=None, warn=True):
433433
"""
434434
Returns an RGBA tuple of four floats from 0-1.
435435
436-
For acceptable values of arg, see to_rgb.
436+
For acceptable values of arg, see to_rgb. In
437+
addition, arg may already be an rgba sequence, in which
438+
case it is returned unchanged if the alpha kwarg is None,
439+
or takes on the specified alpha.
437440
"""
438-
if not is_string_like(arg) and iterable(arg) and len(arg) == 4:
439-
alpha = float(arg[3])
440-
elif alpha is None:
441+
if not is_string_like(arg) and iterable(arg):
442+
if len(arg) == 4 and alpha is None:
443+
return tuple(arg)
444+
r,g,b = arg[:3]
445+
else:
446+
r,g,b = self.to_rgb(arg, warn)
447+
if alpha is None:
441448
alpha = 1.0
442-
r,g,b = self.to_rgb(arg, warn)
443449
return r,g,b,alpha
444450

445451
def to_rgba_list(self, c):

0 commit comments

Comments
 (0)