Color Palette for TH2F

Hi all,
I am having some troubles in trying to build my own color palette for a TH2F.
I would like to plot it in such a way that if the bin content is equal to 1 the color would be white, if the bin content is less than 1 the color would be blueish and if the bin content is larger than 1 the color would be reddish.
I have done something like this:

double min = h11->GetMinimum();
double max = h11->GetMaximum();
double perc = (1. - min)/(max - min); //in order to find the percentage of table from min to 1

int N = 3, NCont = 128;
Double_t stops[N] = { 0.00, perc, 1.00 };
Double_t red[N] = { 0.00, 1.00, 1.00 };
Double_t green[N] = { 0.00, 1.00, 0.00 };
Double_t blue[N] = { 1.00, 1.00, 0.00 };

int FI = TColor::CreateGradientColorTable(N, stops, red, green, blue, NCont);
h11->Draw(â€ścolzâ€ť);

In this way, as far as I understood, it should use for the first â€śpercâ€ť of the table colors for going from blue to white and for the rest colors for going from white to red.
However, it does not seem to do so. I have, for instance, min = 0.951374, max = 1.04497 and perc = 0.51951, but, instead of going from blue to white for the first 51% of the table (which is where 1 is), it arrives at white already for bin content values of 0.975 (around at the 25% of the table).
What am I doing wrong?

Thank you very much for your time and your help!

Best Regards,
Ilenia

``````{
TH2F *h1 = new TH2F("h1","h1",100,-4,4,100,-4,4);
h1->SetStats(0);

Double_t a,b;
for (Int_t i=0;i<50000;i++) {
gRandom->Rannor(a,b);
h1->Fill(a-1.5,b-1.5,0.08);
}

Double_t max       = h1->GetMaximum();
Double_t min       = h1->GetMinimum();
Double_t val_white = 1.;
Double_t per_white = (val_white-min)/(max-min);

const Int_t Number = 3;
Double_t Red[Number]   = { 0., 1., 1.};
Double_t Green[Number] = { 0., 1., 0.};
Double_t Blue[Number]  = { 1., 1., 0.};
Double_t Stops[Number] = { 0., per_white, 1. };

Int_t nb= 256;
h1->SetContour(nb);

TColor::CreateGradientColorTable(Number,Stops,Red,Green,Blue,nb);
h1->Draw("colz");
}

``````

1 Like

Thank you very much!
Using h1->SetContour(nb) fixes the problem!

Thank you again!
Ilenia

Yes, `SetContour` defines the number of levels used to draw the colour plot. By default it is 50. If you have a palette with many colours like in your case, increasing the number of contours allows to have a smother plot. Note that even without `SetContour` the plot is correct.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.