Drawing TH2 "colz" with transparency in color palette


ROOT Version (e.g. 6.12/02): 6.12/06
Platform, compiler (e.g. CentOS 7.3, gcc6.2): macOS, clang 9.1


I would like to draw 2D histograms with “colz” options, but the colors be transparent. Ie, doing this works:

gStyle->SetPalette(kBird,0,0.5);  // default palette with 0.5 for alpha
hist1->Draw("colz");
hist2->Draw("colz same");   // the two histograms will have transparent colors, and overlapping bins are visible

However, this doesn’t work when I define my own color palette:

gStyle->SetPalette(ncolors,mypalette,0.5);  // custom color palette with 0.5 for alpha
hist1->Draw("colz");
hist2->Draw("colz same");   // the two histograms will have opaque colors, and overlapping bins will be overridden by the order of histograms drawing

I am not sure why this shouldn’t work. Any help would be appreciated!

Upon searching a bit further, it seems this issue of transparency in default vs. user-defined color palettes has already been discussed here: https://root-forum.cern.ch/t/multipalette-with-transparency/26372/16

The following is working:

{
   TCanvas *c  = new TCanvas("c","Contours",600,0,600,600);
   TF2 *f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   Double_t Red[5]    = { 1.00, 0.00, 0.00, 0.00, 0.50};
   Double_t Green[5]  = { 0.00, 1.00, 0.00, 0.05, 0.50};
   Double_t Blue[5]   = { 1.00, 0.00, 1.00, 0.50, 0.01};
   Double_t Length[5] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
   Int_t nb=100;
   TColor::CreateGradientColorTable(5,Length,Red,Green,Blue,nb,0.5);
   f2->SetContour(nb);
   f2->Draw("colz");
}

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