# Drawing TH2 "colz" with transparency in color palette

**URL:** <https://root-forum.cern.ch/t/drawing-th2-colz-with-transparency-in-color-palette/28769>\
**Category:** ROOT\
**Created:** [April 21, 2018, 10:31pm UTC](https://root-forum.cern.ch/t/drawing-th2-colz-with-transparency-in-color-palette/28769 "2018-04-21T22:31:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![taehyounpark](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/bcef8e/32.png) [@taehyounpark](https://root-forum.cern.ch/u/taehyounpark)\
**Post date:** [April 21, 2018, 10:31pm UTC](https://root-forum.cern.ch/t/drawing-th2-colz-with-transparency-in-color-palette/28769/1 "2018-04-21T22:31:14Z")

</div>

* * *

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:

```auto
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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![taehyounpark](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/bcef8e/32.png) [@taehyounpark](https://root-forum.cern.ch/u/taehyounpark)\
**Post date:** [April 22, 2018, 1:19am UTC](https://root-forum.cern.ch/t/drawing-th2-colz-with-transparency-in-color-palette/28769/2 "2018-04-22T01:19:18Z")

</div>

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](https://root-forum.cern.ch/t/multipalette-with-transparency/26372/16)

---

<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:** [April 23, 2018, 8:42am UTC](https://root-forum.cern.ch/t/drawing-th2-colz-with-transparency-in-color-palette/28769/3 "2018-04-23T08:42:07Z")

</div>

The following is working:

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

```

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 7, 2018, 8:42am UTC](https://root-forum.cern.ch/t/drawing-th2-colz-with-transparency-in-color-palette/28769/4 "2018-05-07T08:42:08Z")

</div>

Closed on May 7, 2018, 8:42am UTC

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