Python draw rectangle and color in range
Question: 
    import brewer2mpl
    import numpy as np
    
    a = np.random.rand(3) # a[0] represents value of rect1, a[1] of rect[2]....
    
    def get_colors():    
        """
        Get colorbrewer colors, which are nicer
        """            
        bmap   = brewer2mpl.get_map('Accent','qualitative',6)
        return bmap.mpl_colors
    
    rect1 = matplotlib.patches.Rectangle((2,2), 1, 1, color='yellow'))
    ax.add_patch(rect1)
    rect2 = matplotlib.patches.Rectangle((3,3), 1, 1, color='green'))
    ax.add_patch(rect2)
    rect3 = matplotlib.patches.Rectangle((5,5), 1, 1, color='red'))
    ax.add_patch(rect3)
    

I would like the color of the rectangle to vary based on the value of the
vector 'a'. Instead of pure yellow/green/red color, select a color from a
range, preferably the brewer2mpl colors


Answer: From what I can read, mpl_color is a list of colors. The colors are 3-tuples,
with a range in (0,1) representing the rgb amount. You can set a color to be
such a triple.

    
    
    import pylab as py
    
    py.plot([0,1],[2,3], color = (1,0,0.))
    py.savefig('tmp.png')
    

![enter image description here](http://i.stack.imgur.com/FxZLW.png)

So all you have to do is take the entry in the vector `a` (I'll call it
`avalue` below, with `0<avalue<1`) and map it to an appropriate integer. For
example

    
    
    colorlist = get_colors()
    colorlength = len(colorlist)
    py.plot([0,1],[2,3], color = colorlist[int(avalue*colorlength)])
    

