Use TImage palette for TH2 histograms

Hi all,

Can someone tell me how to use a modified “Rainbow” TImagePalette for TH2 histograms drawn with “colz”? I am able to read in a palette root file that I saved through the palette editor from the state shown in palette.png (note also the lower bound is moved up), but when I grab the palette from the root file and use it on a histogram, I end up with the the default palette (same as in palette_default.png).

Here’s a snippet of code showing how I read the palette (assume h2f is a TH2F histogram that is already filled):

TFile *f1 = new TFile("image.pal.root","READ");
TImagePalette *ip = (TImagePalette *)f1->Get("TImagePalette");
delete f1;

Int_t *in = ip->GetRootColors();

If I read the palette in correctly, then I need guidance on how to apply it because the latter part of the code certainly doesn’t seem to work.


I think, to define a gradient palette, you should use the method shown in this macro:

   TCanvas *c  = new TCanvas("c","Contours",600,0,600,600);
   TF2 *f1 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   UInt_t Number = 3;
   Double_t Red[Number]   = { 1.00, 0.00, 0.00};
   Double_t Green[Number] = { 0.00, 1.00, 0.00};
   Double_t Blue[Number]  = { 1.00, 0.00, 1.00};
   Double_t Stops[Number] = { 0.00, 0.50, 1.00 };
   Int_t nb=50;

The gradient table worked just fine! I have to fiddle with the numbers to get a zero-suppression though, but that’s okay.