How to manipulate the color palette

Hi,

would like to copy an existing palette (from gStyle->SetPalette(1)) and change the colors in it (e.g. change the saturation). Is there any way to do that in a script?
Thanks,

Vinzenz

You can define your own palette doing something similar to the following example:

{
   TF2 *f2 = new TF2("f2","0.1+1000*((1-(x-2)*(x-2))*(1-(y-2)*(y-2)))",1,3,1,3);  
   Int_t ncol = 100;
   Int_t colors[ncol];
   TColor *col;
   Double_t dg=1/(Double_t)ncol;
   Double_t grey=0;
   for (Int_t i=0; i<ncol; i++) {
      colors[i]= i+100;
      col = gROOT->GetColor(colors[i]);
      col->SetRGB(grey, grey, grey);
      grey = grey+dg;
   }
   f2->SetContour(ncol);
   gStyle->SetPalette(100,colors);
   f2->Draw("colz");
}

you can use the HLS model (instead of RGB) using:

     TColor::HLStoRGB(hue, lightness, saturation, r, g, b);

Thanks for the tip, but now I only know how to create my own palette filled with values I’ve calculated myself, but is there any possibility to read the color array that is used by SetPalette(1), so that I can use these colors as a basis for my new palette?
Or where can I find the code that generates that palette?

Something like that should work:

int icol;
TColor *col;
for (int i=0; i<colors; i++) {
   icol = gStyle->GetColorPalette(i); 
   col = gROOT->GetColor(icol);
   col->GetRGB(r,g,b);
}

Thanks for the tip, I’ve tried it and it works wonderful, thanks again!