Auto color selection PIL

Leif K-Brooks eurleif at ecritters.biz
Wed Sep 27 17:45:45 EDT 2006


Xiaolei wrote:
> I'm trying to plot some points in an image.  Each point has an
> associating type and I'd like to have different colors (preferrably of
> high contrast) for different types.  The number of types in the data
> file is unknown a priori.  Is there a way to do this at runtime?

How about:

from colorsys import hsv_to_rgb

def colors(n):
     incr = 1.0 / n
     hue = 0.0
     for i in xrange(n):
         r, g, b = hsv_to_rgb(hue, 1.0, 1.0)
         yield int(r*255), int(g*255), int(b*255)
         hue += incr



More information about the Python-list mailing list