I have some TBoxes to fill with a color proportional to a number. Every Box has a different number. Now I’m using the default palette. Can I modify the palette for example with the palette used by TGraph2D? The problem is: if I modify the palette then the other objects that use the palette (like TPad) change their colors?
Here is an example showing how to modify a palette. It sets gray levels.
{
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 = 50;
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(ncol,colors);
f2->Draw("cont4 z");
}
You do not necessarely need to use TPalette. You can use colors outside a TPalette. Just make sure, like in this example, that the color indeces you modify are in a range where they will not touch the standard colors.