somewhat OT: function to produce n as distinct colors as possible

Mitja nun at meyl.com
Wed Jun 16 04:49:08 EDT 2004


Edvard Majakari <edvard+news at majakari.net>
(news:87pt7zrkcp.fsf at titan.staselog.com) wrote:
> Ok, not strictly Python related: I wonder if any of you graphical
> Python folks have run accross some handy resource for the given topic.
>
> The problem is that of producing histograms, where n distinct items
> can be plotted simultaneously. However, when n goes over 6 it is not
> very easy to make up colors that are easily distinguishable from each
> other. So, now
> I'm thinking of two alternatives:
>
> 1. Create an algorithm distinct_colors(n, bg), which produces n-1 as
>    distinct colors as possible (where bg is one of the colors) and
>    returns those colors in RGB color model as tuple of decimals (r,
> g, b).
>
>    Eg. distinct_colors(4, (255, 255, 255)) would return
>
>    ((255, 0, 0), (0, 255, 0), (0, 0, 255))
>
>   assuming that "pure-rgb" red, green and blue are visually the three
>   as distinct colors as possible from white.

I'd start with the HSI (aka HSL) model and distribute hues evenly. Don't
know if that's the best solution what with all the stuff going on in our
brain mangling our perception, but it should be close.
Have a look at google for the HSI model and its conversion to RGB.

> 2. Find a color palette containing say, 8 or 10 colors as visually
>    far apart from each other as possible
>
> The first one would be more nice, but I doubt I can produce it myself
> without any knowledge of psychology and physics related to phenomenon.
>
> Using google it seemed like there's demand for the algorithm. I'll
> probably publish the code in Python Cookbook or similar if I end up
> with something nice.





More information about the Python-list mailing list