Search code examples
pythoncolorsprotovis

Protovis-style color scale in Python?


I've used protovis for some data visualization and I really like its pv.Scale.linear(...).range(...) feature that can be used to create a color scale that maps numerical values to colors. Are there any similar modules for Python that output RGB?


Solution

  • Take a look at the colorsys module in the standard library. That might be useful. As an example, if you want to get the RGB values of a range of fully saturated colors, you can do like this:

    import colorsys
    
    def rgb_range(color_num):
        h_rng = [ix / float(color_num) for ix in range(color_num)]
        return [colorsys.hsv_to_rgb(h, 1.0, 1.0) for h in h_rng]