# Set palette of histogram

**URL:** <https://root-forum.cern.ch/t/set-palette-of-histogram/32152>\
**Category:** ROOT\
**Created:** [January 2, 2019, 4:25pm UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152 "2019-01-02T16:25:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![hajar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/d9b06d/32.png) [@hajar](https://root-forum.cern.ch/u/hajar)\
**Post date:** [January 2, 2019, 4:25pm UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/1 "2019-01-02T16:25:50Z")

</div>

* * *

\_ROOT Version:5.34/10

* * *

Hi,  
I have a two dimensional histogram that has positive and negative values. I use TColor::CreateGradientColorTable  
to set the palette but I have the same colour(white) for zero values of histogram and those region of histogram that don’t have values. How can I differ these parts from the real zero values?  
Thanks

---

<div class="post-metadata">

**Author:** ![vaubee](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/v/ecb155/32.png) [@vaubee](https://root-forum.cern.ch/u/vaubee)\
**Post date:** [January 4, 2019, 3:03pm UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/2 "2019-01-04T15:03:14Z")

</div>

What do you mean with “don’t have values”? Do you mean bins that haven’t been set to any value or haven’t been filled? Those are indistinguishable from bins that have been set to zero because when you create the histogram all bins are initialized to zero.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [January 7, 2019, 10:26am UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/3 "2019-01-07T10:26:06Z")

</div>

@couet - do we have a better answer than “set all bins to -1 to signal ‘empty’ and then draw with range”?

---

<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 7, 2019, 1:40pm UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/4 "2019-01-07T13:40:41Z")

</div>

When bins have content 0 it is impossible to tell if the bin was never filled or if it was filled many times being in total 0. This is what we explain [here (option COL1)](https://root.cern/doc/master/classTHistPainter.html#HP14). I would suggest you first try to use COL1 instead of COL.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 7, 2019, 1:43pm UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/5 "2019-01-07T13:43:16Z")

</div>

Actually, you could have a signature for “non-empty” bins with “zero contents” …

```auto
histo1D->Fill(x, 1.e-6); histo1D->Fill(x, -1.e-6);

```

Note: [Empty bins are these that have the content equal to zero AND error equal to zero.](https://root.cern.ch/doc/master/classTH1.html#a7e7d34c91d5ebab4fc9bba3ca47dabdd)

---

<div class="post-metadata">

**Author:** ![hajar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/d9b06d/32.png) [@hajar](https://root-forum.cern.ch/u/hajar)\
**Post date:** [January 14, 2019, 10:22am UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/6 "2019-01-14T10:22:28Z")

</div>

Thanks for your answer and sorry for delay,

I mean the bins haven’t been filled.

---

<div class="post-metadata">

**Author:** ![hajar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/d9b06d/32.png) [@hajar](https://root-forum.cern.ch/u/hajar)\
**Post date:** [January 14, 2019, 10:34am UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/7 "2019-01-14T10:34:09Z")

</div>

Thanks for your answer,  
I can’t do it. The histogram has negative and positive values. This is my histogram  
[cos.pdf](https://root-forum.cern.ch/uploads/default/original/3X/2/d/2dd11f8e0541a02e3531ce35262c4280ed424d30.pdf) (47.7 KB)

I set the pallet to have the white colour for zero. There is no difference between the zero values of bins inside the shape and the bins that haven’t been filled around the shape.

---

<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 14, 2019, 10:50am UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/8 "2019-01-14T10:50:12Z")

</div>

May be follow Wille suggestion by putting Epsilons for filled bins close to 0.

---

<div class="post-metadata">

**Author:** ![hajar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/d9b06d/32.png) [@hajar](https://root-forum.cern.ch/u/hajar)\
**Post date:** [January 14, 2019, 11:04am UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/9 "2019-01-14T11:04:16Z")

</div>

Thanks, I couldn’t do this. I have positive and negative values to fill histogram and when I use setpallet I have the white colour for values between -0.01 to 0.01.  
[cos.pdf](https://root-forum.cern.ch/uploads/default/original/3X/a/2/a2d0c4aa3eb9b551aa29382a2a1ffbd5ae9de1e9.pdf) (47.7 KB)

---

<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 14, 2019, 12:27pm UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/10 "2019-01-14T12:27:38Z")

</div>

You should create a palette with more colors such as white will represent only a tiny fraction of the palette around 0.

---

<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:** [January 29, 2019, 5:26am UTC](https://root-forum.cern.ch/t/set-palette-of-histogram/32152/12 "2019-01-29T05:26:05Z")

</div>

Closed on January 29, 2019, 5:26am UTC

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