def _user_to_rgba(color, expand=True, clip=False):
    """Convert color(s) from any set of fmts (str/hex/arr) to RGB(A) array"""
    if color is None:
        color = np.zeros(4, np.float32)
    if isinstance(color, string_types):
        color = _string_to_rgb(color)
    elif isinstance(color, ColorArray):
        color = color.rgba
    # We have to treat this specially
    elif isinstance(color, (list, tuple)):
        if any(isinstance(c, string_types) for c in color):
            color = [_user_to_rgba(c, expand=expand, clip=clip) for c in color]
            if any(len(c) > 1 for c in color):
                raise RuntimeError('could not parse colors, are they nested?')
            color = [c[0] for c in color]
    color = np.atleast_2d(color).astype(np.float32)
    if color.shape[1] not in (3, 4):
        raise ValueError('color must have three or four elements')
    if expand and color.shape[1] == 3:  # only expand if requested
        color = np.concatenate((color, np.ones((color.shape[0], 1))),
                               axis=1)
    if color.min() < 0 or color.max() > 1:
        if clip:
            color = np.clip(color, 0, 1)
        else:
            raise ValueError("Color values must be between 0 and 1 (or use "
                             "clip=True to automatically clip the values).")
    return color
def _user_to_rgba ( color , expand = True , clip = False ) : if color is None : color = np . zeros ( 4 , np . float32 ) if isinstance ( color , string_types ) : color = _string_to_rgb ( color ) elif isinstance ( color , ColorArray ) : color = color . rgba elif isinstance ( color , ( list , tuple ) ) : if any ( isinstance ( c , string_types ) for c in color ) : color = [ _user_to_rgba ( c , expand = expand , clip = clip ) for c in color ] if any ( len ( c ) > 1 for c in color ) : raise RuntimeError ( 'could not parse colors, are they nested?' ) color = [ c [ 0 ] for c in color ] color = np . atleast_2d ( color ) . astype ( np . float32 ) if color . shape [ 1 ] not in ( 3 , 4 ) : raise ValueError ( 'color must have three or four elements' ) if expand and color . shape [ 1 ] == 3 : color = np . concatenate ( ( color , np . ones ( ( color . shape [ 0 ] , 1 ) ) ) , axis = 1 ) if color . min ( ) < 0 or color . max ( ) > 1 : if clip : color = np . clip ( color , 0 , 1 ) else : raise ValueError ( "Color values must be between 0 and 1 (or use " "clip=True to automatically clip the values)." ) return color
Convert color(s) from any set of fmts (str/hex/arr) to RGB(A) array