Dear ROOT team,
I need to plot two 2D histograms, each one with a customized color palette. The histograms should “remember” their color palettes when they are redrawn. Now I know this subject has been discussed before, and I tried to apply the lesson given in root.cern.ch/phpBB2/viewtopic.php?t=2483 , but somehow I must be doing something wrong.
Let me demonstrate this with a slight adaption of the macro given in the aforementioned post:
{
TCanvas *c1 = new TCanvas("c1","c1",400,600);
c1->Divide(1,2);
TH2F *h1 = new TH2F("h1","h1",40,-4,4,40,-4,4);
TH2F *h2 = new TH2F("h2","h2",40,-4,4,40,-4,4);
Double_t a,b;
for (Int_t i=0;i<5000;i++) {
gRandom->Rannor(a,b);
h1->Fill(a-1.5,b-1.5);
h2->Fill(a+1.5,b+1.5);
}
TExec *ex1 = new TExec("ex1","gStyle->SetPalette(0);");
TExec *ex2 = new TExec("ex2","gStyle->SetPalette(1);");
c1->cd(1);
//ex1->Draw();
h1->GetListOfFunctions()->Add(ex1);
h1->Draw("colz");
c1->cd(2);
//ex2->Draw();
h2->GetListOfFunctions()->Add(ex2);
h2->Draw("colz");
c1->Update();
}
Having no luck with ex1->Draw(), I try with GetListOfFunctions()->Add(ex1), but this does not seem to have the desired effect either: I get one palette for the plot, the other palette for the legend, or some weird combination of the two (specially when the macro is executed several times, or a redrawing is triggered with the mouse). The problem is that the palette selection gets executed after the drawing of the histogram. How can I marry a histogram with a color palette once and for all? (it is a pity these color palettes are not properties of the histograms themselves!!)
Many thanks in advance,
Thomas
PS: ROOT 5.16/00