Unique graph colors

Hi ROOTers,

I was wondering if there’s a way to create a list of discernable colors on the fly. e.g. If I want to draw a TMultiGraph with 30 graphs on it and I want to make sure they will be discernable, I would need a simple way of generating 30 discenable colors on the fly (but I don’t care which colors they are).
Does such a thing exist?


I guess the 30 first colors are of that kind. You can also have a look at the color wheel:

Yeah, but the colors on the color wheel are not numbered in a particular order (shades are, but not colors) so the only way I can write a distinct color list is by creating my own array of colors that I selected:

int cols[30] = {kBlue, kRed, kGreen, kBlue+5, etc'};

The first 50 colors are not really distinct (the first 10 are though).

I was thinking something along these lines:

Int_t* TColor::GetColorRange(Int_t nCols, Float_t sat = 1; Float_t val=1.) {
  Int_t* cols = new Int_t [nCols];
  for (Int_t i; i<nCols;i++) {
    Float_t r, g, b;
    Float_t hue;
    hue = ( 360.* i )/nCols;
    cols[i] = TColor::GetColor(r,g,b);
  return cols;

So you have a range of distinct colors moving on the hue line.

Yes, your little macro is a way to proceed.