# Z scale and color pallete

**URL:** <https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765>\
**Category:** Newbie\
**Created:** [January 7, 2024, 1:58pm UTC](https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765 "2024-01-07T13:58:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [January 7, 2024, 1:58pm UTC](https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765/1 "2024-01-07T13:58:55Z")

</div>

Dear Rooters,

In a 2D plot, the z count starts from 10^-2 (with the option ‘colz’).  
When I start it from 1 using hist-\>SetMinimum(1), the color pattern changes which is obvious. How to conserve the same color pattern (of kRainbow=55)?  
I mean is there anything I can change in the ‘Gradient Color Table’ I am using (kRainbow=55)?

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [January 8, 2024, 8:18pm UTC](https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765/2 "2024-01-08T20:18:18Z")

</div>

Hi,

I do not understand very well the question. Perhaps @couet can help here.

Best,  
D

---

<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:** [January 9, 2024, 7:35am UTC](https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765/3 "2024-01-09T07:35:03Z")

</div>

Yes, when you draw a 2D histogram the palette is displayed according to the full dynamic of the histogram. One simple way for your case might be to create a copy of the original histogram in which you will set (with SetBinContent) all the bins having a content \<=1 to 1.

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [January 9, 2024, 3:48pm UTC](https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765/4 "2024-01-09T15:48:13Z")

</div>

Thanks @couet . I am directly reading/taking the 2D histograms from other root files (not by TGraph etc.), in my program. In such case, how can I set all the lower bins having content \<=1 to 1?

Could you please give me an example of the solution you suggested using `SetBinContent’ here?

---

<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:** [January 9, 2024, 3:58pm UTC](https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765/5 "2024-01-09T15:58:30Z")

</div>

```auto
auto f = new TFile ("your_file.root");
TH2F *h = (TH2F *)f->Get("your_hist");
TH2F *hc = (TH2F*)h->Clone();
int nbinsX = h->GetNbinsX();
int nbinsY = h->GetNbinsY();

for (int i = 1; i <= nbinsX; i++) {
    for (int j = 1; j <= nbinsY; j++) {
       if (hc->GetBinContent(i,j) < 1) hc->SetBinContent(i, j, 1.0);
    }
}
hc->Draw("COLZ");

```

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [January 10, 2024, 4:31am UTC](https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765/6 "2024-01-10T04:31:41Z")

</div>

Thanks @couet by doing that the background color turns green. How to restore the pad-background color to white?

---

<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:** [January 10, 2024, 7:12am UTC](https://root-forum.cern.ch/t/z-scale-and-color-pallete/57765/7 "2024-01-10T07:12:27Z")

</div>

As the bins are not empty the “background” colour correspond to the minimum of the histogram: 1 in your case.

May be you need an other technique and define your own palette as described [here](https://root.cern/doc/v630/classTColor.html#C05). You will not need to change this histogram in that case,
