def colorscale(mag, cmin, cmax):
    """
    Return a tuple of floats between 0 and 1 for R, G, and B.
    From Python Cookbook (9.11?)
    """
    # Normalize to 0-1
    try:
        x = float(mag-cmin)/(cmax-cmin)
    except ZeroDivisionError:
        x = 0.5  # cmax == cmin
    blue = min((max((4*(0.75-x), 0.)), 1.))
    red = min((max((4*(x-0.25), 0.)), 1.))
    green = min((max((4*abs(x-0.5)-1., 0.)), 1.))
    return red, green, blue
Return a tuple of floats between 0 and 1 for R, G, and B.
    From Python Cookbook (9.11?)