Color pallete for a set window level and window width


I believe ROOT system does not yet have a feature to set a color window level and width (correct me if I am wrong).

For that reson, I have been looking into ways for creating a customized colour pallette and a colour table such that the minimum hsitogram cell value corresponds to the first element in the customized colour pallete, from which the colour index gives the colour vector (to be generated by the TColor::CreateGradientColorTable(). That was my plan.

However, colour pallete’s starting index begins from 0, and since my cell values usually starts from a large number (many tens of thousands), it means a large range of the customized color pallete index range is of no real use.

Question: Is there a way to create a colour pallete such that the first element maps to a user-chosen histogram cell value? (in order to exploit the full scale range of the color table). Otherwise, I will be using only a small portion of the the customized color table.

It would be greater if you can point me in the right direction or to some existing sample codes for that purpose.

Thanks for help.

Answer: no

The first element of the palette correspond to the minimum of the histogram and the last element to the maximum. The way to do what you are looking for is to set the color palette such as the color is the same between the minimum of the histogram and the first value you want to map.


Thanks for the quick reply.

If the first element of the colour paleete corresponds to the min histogram cell value and the last element to the max histogram cell value, that will work fine to me. But I am wondering how you do that.

Say the histogram cell values is between 9000-10000. The range is 1000 (offset 9000). I create a colour pallete and color table with 100 elements.

Since there the cell values is greater the number of colors, the histogram will automatically “rescale”?. If so, the first 90 colors will go to 0-9000; the remaning 10 colors will be used from 9000-10000. That is my current understanding.

How you do instruct the histogram such that all the 100 colors are distributed to the range between 9000-10000. (ie. the 9000 is the first element of the color palette, which maps to the first color)?



  • 100 colors
  • range on the Z axis for 9000 to 10000
  • step for one color: (10000-9000)/100 =10
    1st color from 9000 to 9010
    2st color 9010 to 9020
    etc …


I undestand your explanation, but I don’t seem to be seeing what you described. The colour pallete (the Zaxis) does not indicate that the minimum corresponds to the first pallete value (It starts from 0).

In the following example, I know the cell value ranges from about 10,000 to 19,000.

I adapted pal1 color pallete from the example in TColor documentation.

void Pal1()
static Int_t colors[50];
static Bool_t initialized = kFALSE;

Double_t Red[3] = { 1.00, 0.00, 0.00};
Double_t Green[3] = { 0.00, 1.00, 0.00};
Double_t Blue[3] = { 1.00, 0.00, 1.00};
Double_t Length[3] = { 0.00, 0.50, 1.00 };

Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);

for (int i=0; i<50; i++) colors[i] = FI+i;


I get the following image when I use the pallete for display:

I am expecting about 50 colours, and the minimum should starts from about 10,000.
I am seeing 20 colours on the displayed colour pallete, and the minimum starts from 0.

There is one note: The histogram data is loaded by TH2D:SetConten(ArranyD) in one array load; not one element at a time. Not sure if this affected the result or not. I also used TH2D:Setminimum() and TH2D:SetMaximun() to make sure the min and max are set.

Any explanation why I am not seeing the 50 colours and that first colour does not correspond to the minimum (~10,000)?


You are absolutely right!!

My histogram was declared with sizes that were a couple of rows bigger than the available data. This leaves a couple of rows of zeros. This explains why the first color element corresponds to zero.

However, I think I am still seeing only 20 colors instead of 50 colors in the color palletes, or it is an optical illusion?

I also tried using 100 colors, with no observed improvement.


set the number of contours to 50 (default is 20)



That was it!!!

Thanks. How did you know that!!!???