Transparency as Color Palette Key

Hi all,

is there any way to have a color palette with a single RGB color and varying alpha value depending on the bin content?
So far, I have only seen solutions for having a fixed transparency value for a color palette with varying RGB value. But as shown in the OpenGL grad2 tutorial, it is also possible to have a gradient fill with changing alpha value. Can this somehow be translated to a color palette for drawing a TH2 with COLZ option?


ROOT Version 6.12/06 or 6.13/02:
Ubuntu 16.04, gcc5.4:

void monotranspal() {
   const Int_t NBCol = 50;
   Int_t ci;
   Int_t icol[NBCol];
   Float_t da = 1./NBCol, alpha = 0.;

   // Define a palette with a fix color (red) varying in alpha
   for (int i=0; i<NBCol; i++) {
      ci = TColor::GetFreeColorIndex();
      alpha = alpha+da;
      TColor *color = new TColor(ci, 1., 0., 0., Form("c%d",i), alpha);
      icol[i] = ci;
   gStyle->SetPalette(NBCol, icol);

   // Draw an histo with the defined palette
   TH2F *histo2=new TH2F("histo2","name",20,0,20,20,0,20);
   TF2 *dist=new TF2("dist","[0]+[1]*x+[2]*y",0,20,0,20);

Thank you, works like a charm!

1 Like

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