Multipalette with transparency

Agreed works with predefined palette (zoom is still an issue).

I am using 6.10/02. Does the example I sent work for you?

I revised your example to use predefined palettes and it sort of works, although the behavior is not what I expected. I would have thought pad 1 is kBird, pad 2 is 'kCherry and pad 3 is a mix, but pads 2 and 3 are switched? If I click on pad 2 it refreshes and turns back to complete kCherry. (Also, worked in 6.10.02 on Cocoa for me.)
revised_example

void Pal1() {
    gStyle->SetPalette(kBird, 0, 0.5);
}

void Pal2() {
  gStyle->SetPalette(kCherry, 0, 0.5);
}

TCanvas *test() {
   TCanvas *c3  = new TCanvas("c3","C3",0,0,600,400);
   gStyle->SetCanvasPreferGL(kTRUE);
   c3->Divide(3,1);
   TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   TF2 *f4 = new TF2("f4","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   f3->SetLineWidth(1);
   f3->SetLineColor(kBlack);

   c3->cd(1);
   f3->Draw("col");
   TExec *ex1 = new TExec("ex1","Pal1();");
   ex1->Draw();
   f3->Draw("col same");

   c3->cd(2);
   f4->Draw("col");
   TExec *ex2 = new TExec("ex2","Pal2();");
   ex2->Draw();
   f4->Draw("col same");

   c3->cd(3);
   Pal1();
   f3->Draw("col");
   TExec *ex3 = new TExec("ex3","Pal2();");
   ex3->Draw();
   f4->Draw("col same");

   return c3;
}

Yes it is the mixing of TF1 and TF2 lose the zooming mechanism

1 Like

Using this script I can reproduce your intended behavior, but I have to click on pad 2 to get only the transparent kCherry. Also, when changing zooms (in or out) you get different combinations of the palettes in each pad, clicking on it after the zoom restores it to the expected palette.

revised_example2

void Pal1() {
     gStyle->SetPalette(kBird, 0, 0.5);
}

void Pal2() {
   gStyle->SetPalette(kCherry, 0, 0.5);
}

TCanvas *test() {
   TCanvas *c3  = new TCanvas("c3","C3",0,0,600,400);
   gStyle->SetCanvasPreferGL(kTRUE);
   c3->Divide(3,1);
   TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);

   c3->cd(1);
   f3->Draw("col");
   TExec *ex1 = new TExec("ex1","Pal1();");
   ex1->Draw();
   f3->Draw("col same");

   c3->cd(2);
   f3->Draw("col");
   TExec *ex2 = new TExec("ex2","Pal2();");
   ex2->Draw();
   f3->Draw("col same");

   c3->cd(3);
   f3->Draw("col");
   TExec *ex3 = new TExec("ex3","Pal1();");
   ex3->Draw();
   f3->Draw("col same");
   TExec *ex4 = new TExec("ex4","Pal2();");
   ex4->Draw();
   f3->Draw("col same");
}

It does not work for me. I get the same for panels 2 and 3. Why doesn’t
it work for custom palettes, anyway? It looks like something fishy is
going on.

@couet Is investigating, we will have to wait to see what he finds.

Ok here is a simpler and working version of the @ksmith example. Now give me some tome to investigate why the user defined one cannot be transparent.

void transpal2() {
   TCanvas *C  = new TCanvas("C","C3",0,0,600,400);
   gStyle->SetCanvasPreferGL(kTRUE);
   C->Divide(3,1);
   TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);

   // Pad 1 is kBird
   C->cd(1);
   gStyle->SetPalette(kBird);
   f3->Draw("col");

   // Pad 2 is kCherry
   TExec *ex2 = new TExec("ex2","gStyle->SetPalette(kCherry);");
   ex2->Draw();
   C->cd(2);
   f3->Draw("col");

   // Pad 3 is 0.5 * kBird + 0.5 kCherry
   TExec *ex3 = new TExec("ex3","gStyle->SetPalette(kBird, 0, 0.5);");
   ex3->Draw();
   C->cd(3);
   f3->Draw("col");
   TExec *ex4 = new TExec("ex4","gStyle->SetPalette(kCherry, 0, 0.5);");
   ex4->Draw();
   f3->Draw("col same");

   // Reset kBird
   TExec *ex5 = new TExec("ex2","gStyle->SetPalette(kBird);");
   ex5->Draw();
}

This example is very strange when you click on all the pads (maybe we leave this until the custom palette transparency is resolved first).
Before clicking:
couet
After clicking:
couet_clicked

This canvas need to executed completely to work. If you click you execute only a single pad and the palette sequencing is lost. You can resize though

It does not work for me. I am running on Ubuntu 16.04. Attached is a
screen-shot of what I get. I click on pad 2 and nothing happens. I zoom
in and out, and I don’t see any color changes on any of the panels.
Other examples of transparency work for me, like transp.C.

Pablo

On what OS are you running? None of the examples sent work for me.

Mac. Try to change the system.rootrc file instead of setting PreferGl in the macro (see TColor doc);

Does this one work for you:

https://root.cern/doc/master/transparency_8C.html ?

Got it. I changed the system.rootrc file and now it works for your
example. Still the custom palette remains.

Thanks,

Pablo

Back to the initial question, I confirm that via SetPalette the alpha parameter is taken into account only for predefined palettes (may be the doc will need to be clarified there) . For the user defined palettes it is up to the user to put transparent colors in the palette. With the code you wrote you can do it with the last parameter of CreateGradientColorTable

   if(!initialized){
      Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50, 0.5);
      for (int i=0; i<50; i++) colors[i] = FI+i;
      initialized = kTRUE;
   }
   gStyle->SetPalette(50,colors);

But, still that it is not what I would like to do. I would to
superimposed two different 2d histos with different palettes. You are
just plotting one histogram with a mixture of palettes.

{
   TCanvas *c1 = new TCanvas("c1");

   TH2F *h1 = new TH2F("h1","h1",40,-4,4,40,-4,4);
   TH2F *h2 = new TH2F("h2","h2",40,-4,4,40,-4,4);
   Double_t a,b;
   for (Int_t i=0;i<5000;i++) {
      gRandom->Rannor(a,b);
      h1->Fill(a-1.5,b-1.5);
      h2->Fill(a+1.5,b+1.5);
   }
   TExec *ex1 = new TExec("ex1","gStyle->SetPalette(kBird);");
   TExec *ex2 = new TExec("ex2","gStyle->SetPalette(kCherry,0,0.5);");
   h1->Draw("col");
   ex1->Draw();
   h1->Draw("col same");
   ex2->Draw();
   h2->Draw("col same");
}

1 Like

I am almost there. Actually, it looks like I can use a couple of
predefined palettes. However, I have one more problem.

Look at the attached macro. You will also need the attached input file.
Notice that the color scale for h2 on panel 1 is not right. The right
scale is shown on panel two where h2 is plotted alone.

I also need to flip the y axis of the histograms. I would like to show
the -350 at the top and -150 at the bottom. Is there a quick way to do that?

Thank you,

Pablo

test3.cxx (555 Bytes)

example-figures.root (177 KB)

The attache macro gives the following plot. The problem with you version was that when an histogram ins drawn with the option SAME it uses the ranges defined by the previously drawn histogram on X Y et Z axis. To workaround this you need to draw the 2nd histogram in a transparent pad overplayed on the already drawn histogram. That’s what the attached macro does .

yepes2.C (808 Bytes)

There is no easy way to do that. The example https://root.cern/doc/master/reverseaxis_8C.html shows how to do it. But be careful that it simply draws the axis upside down ! you will need to make a new histogram mirroring the bins.

One side comment:

Even if ROOT provides the RainBow color map, it is not a recommended palette to visualise data, as explained in this article.