Question

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?

Was it helpful?

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]

OTHER TIPS

For anyone who wants to see what I ended up doing, here's the link:

Color Scale on Pastebin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top