Managing the 1D palette

Hi,

There are many topics about how to manage the palette for 2D histograms, but I can’t figure out how to change the 1D palette (ie for TH1F, TGraph, TMarker, TLine…).

The 1D and 2D palettes seem not to be related. This is obvious, for instance, when you try the following :

gStyle->SetPalette(1); somegraph->SetLineColor(5); somegraph->Draw("al");

But this is not quite straightforward why. TAttLine documentation says that DrawColorTable() shows “the first 50 default colors”, implying that there must be a way to change these default values (in my opinion the user expect this behaviour when changing the palette, but anyway).

I cannot figure out the way to achieve this. Can anybody point me to the right documentation or explain it ?

Thanks.

Ok, I figured it out (the right term to search for was TColor). To change a color of the current (1D) palette :

TColor *c=gROOT->GetColor(5); c->SetRGB(1.,0,0);

Then calling SetLineColor(5) will get the red color. It should be easy to play with this to obtain a smooth palette like this one, but isn’t there a cleaner/preferred method than changing all the default values manually ?

Ok, now I get it. The simplest way to define one’s own 1D palette is to define a custom palette as explained almost everywhere (for instance on TColor’s doc or here), then to call :

which will give the index of the first color defined in this palette. Then you just have to call SetLineColor or whatever starting from this index up to this index plus the number of colors defined in your custom palette.

Maybe this could be made more clear in the documentation — unless I missed something, obviously.

BTW, maybe the DrawColorTable could be adapted to DrawColorTable(int index, int ncolors) to show the table of the ncolors starting from index.

The last example here root.cern.ch/root/html/TColor.html shows hows to retrieve the first index of a user defined palette (FI)