Color gradient in root

How to create a color gradient in cern root for graphs. Suppose I have 100 graphs plotted on a same canvas and I want to give a different color to each graph using a color gradient, then how to do it?

There are many predefined colours in ROOT, see the TColor class reference; you can call 47 (ignoring white) by number (see “Basic colors”), or many more by name +/- a number (see “Color wheel”), or even create your own by defining the R, G and B values (“Introduction”).
To assign them to the line of a graph you just do

mygraph->SetLineColor(yourcolor);   // same for histograms

e.g. mygr1->SetLineColor(4);, mygr2->SetLineColor(kRed+2);, etc)

I have total 100 Grapphs, above 50 it only shows white color in basic color. Also I didn’t understood that after creating a Int_t FI = TColor::CreateGradientColorTable(5, Length, Red, Green, Blue, 100);
how can I get a unique number which I can assign to graph[I]->SetLineColor(number)

You do not need to set the line color. You can use the automatic coloring as explained here:
https://root.cern/doc/master/classTGraphPainter.html#GrP5

Thanks. I worked. Just have a small doubt, since each color palette has 255 colors in each, if we have only 100 graphs, then will it equally distribute all the colors or it will distribute first 100 from the 255 in the color palette?

It will be equally distributed on the palette.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.