pySAXS.guisaxs.pySaxsColors — pySAXS 77.September2012 documentation

### Navigation

- index
- modules |
- pySAXS 77.September2012 documentation »
- Module code »

# Source code for pySAXS.guisaxs.pySaxsColors

    from matplotlib import colors
    #import numpy

    '''
    module for matplotlibwx colors
    '''

    def rgb2luminance(r,g,b):
            return (0.2126*r) + (0.7152*g) + (0.0722*b)

    def name2luminance(name):
        cc=colors.ColorConverter()
        rgb=cc.to_rgb(name)
        return rgb2luminance(rgb[0],rgb[1],rgb[2])

    def listOfColors():
        '''
        return the RGB list of colors  with luminance <=0.4
        '''
        k=colors.cnames.keys()
        l=[]
        for name in k:
            #print name,
            if name2luminance(name)<=.4:
                #print "append ", name
                #l.append(name)
                l.append(colors.cnames[name])
        #l.sort()
        return l

    def listOfColorsNames():
        '''
        return the list of colors NAMES with luminance <=0.4
        '''
        k=colors.cnames.keys()
        l=[]
        for name in k:
            #print name,
            if name2luminance(name)<=.4:
                #print "append ", name
                #l.append(name)
                l.append(name)
        #l.sort()
        return l

    def listOfColorsDict():
        k=colors.cnames.keys()
        d={}
        for name in k:
            #print name,
            if name2luminance(name)<=.4:
                d[name]=colors.cnames[name]
        return d

    def getColorRGB(name):
        if colors.cnames.has_key(name):
            return colors.cnames[name]
        else:
            return colors.cnames['black']

### Navigation

- index
- modules |
- pySAXS 77.September2012 documentation »
- Module code »