Using Tcolor, color palette

Hello ROOTers,

I’m using the following script to display 2-d histograms with color.

   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 Length[Number] = { 0.00, 0.50, 1.00 };
   Int_t nb=50;
   TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);

root.cern.ch/root/html/TColor.html

The issue i have is when i zoom the scale, the root recalculate the color range and change the color for data values.
I think this is because root uses the stops as fraction of whole range.
Int_t CreateGradientColorTable(UInt_t Number, Double_t* Stops, Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors, Float_t alpha = 1.)
So if you change the zoom scale(data range) you will get different color for a given data value.
I want the same color for the same data value even if i change the zoom range.
For example, i have data spanning negative to positive values in a 2-d histogram and i want ‘zero’ allways have the same color.
Can i do it?
If then, how?

It would be very appreciated if you could give some help on this issue.
Thanks,

You mean the X or Y scale ?

[quote=“couet”][quote]
The issue i have is when i zoom the scale, the root recalculate the color range and change the color for data values.
[/quote]

You mean the X or Y scale ?[/quote]

No, i meant color scale.
I draw the histogram using “colz” option.

can you provide a small macro ?

Try this and change the zoom using your mouse and see what happens on the color chart.
Thanks!

{
TCanvas c2 = new TCanvas(“c2”,“c2”,0,0,600,400);
TF2 f2 = 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 Length[Number] = { 0.00, 0.50, 1.00 };
Int_t nb=50;
TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
f2->SetContour(nb);
f2->Draw(“surf1z”);
return c2;
}

This issue has been solved by using the following two functions.
h->SetMinimum();
h->SetMaximum();

Thanks!

Yes I was about to suggest that … :slight_smile: