# Multipalette with transparency

**URL:** <https://root-forum.cern.ch/t/multipalette-with-transparency/26372>\
**Category:** ROOT\
**Created:** [September 28, 2017, 10:01pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372 "2017-09-28T22:01:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yepes](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/ba8739/32.png) [@yepes](https://root-forum.cern.ch/u/yepes)\
**Post date:** [September 28, 2017, 10:01pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/1 "2017-09-28T22:01:05Z")

</div>

I would like to superimpose two 2D histograms plotted with option “col” and two different palettes and each plot with certain degree of transparency. I tried to do it with the example in multipalette.C, by adding transparency in the definition of the palettes. It did not work for me. I am attaching the modified example. Any help would be appreciated.

```auto
/// \file
/// \ingroup tutorial_graphs
/// \notebook
/// Draw color plots using different color palettes.
///
/// \macro_image
/// \macro_code
///
/// \author Olivier Couet

#include "TStyle.h"
#include "TColor.h"
#include "TF2.h"
#include "TExec.h"
#include "TCanvas.h"

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 };

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

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

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

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

TCanvas *multiPaletteTransparency() {
   TCanvas *c3 = new TCanvas("c3","C3",0,0,600,400);
   gStyle->SetCanvasPreferGL(kTRUE);
   c3->Divide(2,1);
   TF2 *f3 = new TF2("f3","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");
   f3->Draw("col same");

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

   return c3;
}

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 29, 2017, 6:47am UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/2 "2017-09-29T06:47:52Z")

</div>

The transparency does not work for all graphics backends (X11 does not have it for instance)  
See:  
[https://root.cern/doc/master/classTColor.html#C07](https://root.cern/doc/master/classTColor.html#C07)

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [September 29, 2017, 1:51pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/3 "2017-09-29T13:51:14Z")

</div>

@couet Is it even possible to set different palettes for different histograms? I believe my experience indicates that as soon as `gStyle->SetPalette` is called the previously plotted histograms will change palettes when the pads are updated.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 29, 2017, 1:54pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/4 "2017-09-29T13:54:11Z")

</div>

> [@ksmith](#):
>
> Is it even possible to set different palettes for different histograms?

Yes, as shown in [this tutorial](https://root.cern/doc/master/multipalette_8C.html),

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [September 29, 2017, 1:57pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/5 "2017-09-29T13:57:33Z")

</div>

Sorry I should have read the original post more clearly. Thanks for the link.

---

<div class="post-metadata">

**Author:** ![yepes](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/ba8739/32.png) [@yepes](https://root-forum.cern.ch/u/yepes)\
**Post date:** [September 29, 2017, 2:00pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/6 "2017-09-29T14:00:10Z")

</div>

I used

gStyle-\>SetCanvasPreferGL(kTRUE);

to set the canvas to OpenGL. Doesn’t that work?

Pablo

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 29, 2017, 2:04pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/7 "2017-09-29T14:04:45Z")

</div>

> [@yepes](#):
>
> Doesn’t that work?

it should but it also depends which root version you are using… if it is too old it won’t work.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [September 29, 2017, 2:17pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/8 "2017-09-29T14:17:59Z")

</div>

I just tested the transparency of a figure plotted with `"COL"` on ROOT 6.10.06 with a TF1 plotted underneath a TF2 on the Cocoa back end and did not get a transparent image as expected. (Also tried including `gStyle->SetCanvasPreferGL(true)` with no success, not sure it has any affect on a Mac.)

 ![no_trans](https://root-forum.cern.ch/uploads/default/original/2X/f/fb50a0d654eb3a26df68310d140af055a17f3650.png)

```auto
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 };

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

void example() {
   Pal1();

   TF1 *f2 = new TF1("f2","x",1,3);
   TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);

   f2->Draw();
   f3->Draw("col same");
}

```

Also, when I try to zoom in I get a weird behavior:

 ![weird_zoom](https://root-forum.cern.ch/uploads/default/original/2X/f/fced7229ddceba2a3fe7b4c657572d4fbb5ebf1e.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 29, 2017, 2:28pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/9 "2017-09-29T14:28:18Z")

</div>

Yes you are right … it works on predefined palette though. Try:

```auto
gStyle->SetPalette(kBird,0,0.5);

```

It might be it is not implemented for user define palette . I will check.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [September 29, 2017, 2:30pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/10 "2017-09-29T14:30:09Z")

</div>

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

 ![predefined](https://root-forum.cern.ch/uploads/default/original/2X/a/a25638aaf2bc488d16c672fbf93b70ad77e3133a.png)

---

<div class="post-metadata">

**Author:** ![yepes](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/ba8739/32.png) [@yepes](https://root-forum.cern.ch/u/yepes)\
**Post date:** [September 29, 2017, 2:30pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/11 "2017-09-29T14:30:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [September 29, 2017, 2:37pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/12 "2017-09-29T14:37:43Z")

</div>

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](https://root-forum.cern.ch/uploads/default/original/2X/0/062c50d348a7f11de3e22c327e838edcbd13b517.png)

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 29, 2017, 2:45pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/13 "2017-09-29T14:45:25Z")

</div>

> [@ksmith](#):
>
> (zoom is still an issue).

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

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [September 29, 2017, 2:51pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/14 "2017-09-29T14:51:31Z")

</div>

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](https://root-forum.cern.ch/uploads/default/original/2X/b/bb20299f48a53233e0a08fb25d9a7d2e2589008f.png)

```auto
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");
}

```

---

<div class="post-metadata">

**Author:** ![yepes](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/ba8739/32.png) [@yepes](https://root-forum.cern.ch/u/yepes)\
**Post date:** [September 29, 2017, 2:57pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/16 "2017-09-29T14:57:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [September 29, 2017, 3:03pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/17 "2017-09-29T15:03:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 29, 2017, 3:12pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/18 "2017-09-29T15:12:02Z")

</div>

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.

```auto
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();
}

```

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [September 29, 2017, 3:16pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/19 "2017-09-29T15:16:15Z")

</div>

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](https://root-forum.cern.ch/uploads/default/original/2X/9/9b67eba4c060db1ca0c1f522ed7c25413ea78c5b.png)  
After clicking:  
 ![couet_clicked](https://root-forum.cern.ch/uploads/default/original/2X/f/fbbd39ec385241518fcf04b0bd7327abf9dff2e4.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 29, 2017, 3:21pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/20 "2017-09-29T15:21:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yepes](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/ba8739/32.png) [@yepes](https://root-forum.cern.ch/u/yepes)\
**Post date:** [September 29, 2017, 3:20pm UTC](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/21 "2017-09-29T15:20:05Z")

</div>

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

 ![](https://root-forum.cern.ch/uploads/default/original/2X/8/8398ed0ab9f5b8184366687e67e8a6845f34d88c.png)

[Next page](https://root-forum.cern.ch/t/multipalette-with-transparency/26372.md?page=2)
