Inverted grey-scale pallete?

Hi,

I have a small macro which defines a grey palette which I probably copied from the rootalk list years ago. It’s great (see figure) but I would like to invert it, that is white<->black. The benefit will be that small bin contents are very light grey which blends into the white (zero bin contents). Sounds easy but I’m having a devilish time of it (my attempts always end up with some color in them) and wonder if someone already has the solution.

mike


greyscale_example.C (301 Bytes)
grey_pallete.C (481 Bytes)

it is enough to loop on grey levels the reverse way. So, in your macro, it should be enough to do:

double dcol = -1/double(ncol);
double gray = 1;

Hi Olivier,

[quote=“couet”]it is enough to loop on grey levels the reverse way. So, in your macro, it should be enough to do:

double dcol = -1/double(ncol); double gray = 1; [/quote]

Thanks, this does work. It was actually the very first thing I tried but if you look closely at the grey_pallete.C macro (and the TStyle header!) you can see that I have a bug:

gStyle->CreateGradientColorTable(ncol, red,green,blue,stops,totcol);

“stops” should preceed “red”. The tricky thing is that it works as written for the orignal grey pallete but not when inverted. Thanks for helping me see through this one.

mike

{
   TCanvas *c  = new TCanvas("c","Contours",600,0,600,600);
   TH2* h = new TH2F("h","h",20,0,2,20,-2,2);
                                                                                
   for(int i=0; i<100000; i++){
     double x=gRandom->Exp(1);
     double y=gRandom->Gaus(0,1);
     h->Fill(x,y);
   }
                                                                                
   UInt_t Number = 2;
   Double_t Red[Number]   = { 0.00, 1.00};
   Double_t Green[Number] = { 0.00, 1.00};
   Double_t Blue[Number]  = { 0.00, 1.00};
   Double_t Stops[Number] = { 0.00, 1.00};
                                                                                
   Int_t nb=50;
   TColor::CreateGradientColorTable(Number,Stops,Red,Green,Blue,nb);
   h->Draw("colz");
}