# Custom palette in JSROOT

**URL:** <https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090>\
**Category:** ROOT\
**Tags:** jsroot\
**Created:** [August 29, 2025, 8:18am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090 "2025-08-29T08:18:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dondo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dondo](https://root-forum.cern.ch/u/dondo)\
**Post date:** [August 29, 2025, 8:18am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/1 "2025-08-29T08:18:39Z")

</div>

Dear JSROOT experts,

I would need help setting up custom palette for TH2D histograms in JSROOT. Is there some built-in method for doing this? My issue is that I need to mask bins with empty content (make them appear as white), while non-0 values will follow palette color scheme. Since I have both positive and negative values in the histogram, 0 values (or empty bins) get the middle color from the palette and not white. The palette I would like to achieve looks ideally like this:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/6/e/6ebd874e44f9015a39fa270edf466f6d3a3829a9.png)

So there are different colors for positive and negative values and empty bins are ignored - white.

Currently the same plot in plain JSROOT looks like this:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/9/b/9bc63c1998ab99a67260f1045998199aa5d01d2f.png)

Thanks a lot for your suggestions and help.

Best,

Dominik

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [August 29, 2025, 8:35am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/2 "2025-08-29T08:35:45Z")

</div>

Hi Dominik,

Did you try to use “COL1“ draw option?

It introduced exactly for such purposes.

See [ROOT: THistPainter Class Reference](https://root.cern/doc/v636/classTHistPainter.html#HP01c)

Regards,

Sergey

---

<div class="post-metadata">

**Author:** ![dondo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dondo](https://root-forum.cern.ch/u/dondo)\
**Post date:** [August 29, 2025, 8:55am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/3 "2025-08-29T08:55:45Z")

</div>

Hello @linev ,

thanks, you are right, this is indeed the solution 🙂 . However, it would still be nice to have possibility to create custom palette. For other plot I struggled to create palette with distinct colors for each integer value. I ended up with setting fContour to list of color limits and choosing palette that have contrasting colors (55). This resulted in something like this:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/a/8/a8b3d692cb1b9ed477f6bbdf62d8188a3ea16397.png)

It works fine, just i do not understand why first two colors (blue) are the same. I use this as Contour limits:

h\_cov.fContour = [0, 0.5, 1, 2, 3, 4, 5];

h\_cov.fMinimum = 1;

h\_cov.fMaximum = 4.5;

Do you have any suggestion here to achieve separate color for values 1,2,3, etc.?

Best,

Dominik

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [August 29, 2025, 11:18am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/4 "2025-08-29T11:18:03Z")

</div>

> [@dondo](#):
>
> just i do not understand why first two colors (blue) are the same

Yes, strange. I will investigate it.

To configure custom contour levels, you also should set `kUserContour` bit in histogram. Like:

```auto
hist.SetBit(1024, true);

```

For the moment it is not possible to configure fully custom palette from JavaScript side.

Only usecase when custom palette configured in ROOT session and then TCanvas stored in the file - JSROOT able to detect this and will display objects in the TCanvas with such custom palette.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [August 29, 2025, 1:10pm UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/5 "2025-08-29T13:10:26Z")

</div>

I don’t know if this works for JSROOT, but maybe you can give it a try and see (it might also explain why you get two bins with the same colour):

> [@How to set color with \`gStyle-\>SetPalette\` for first bin and last bin? may be bugs](https://root-forum.cern.ch/t/how-to-set-color-with-gstyle-setpalette-for-first-bin-and-last-bin-may-be-bugs/59457/6):
>
> Create a text file (e.g. “mycolours.txt”) with the RGB values (one colour per line, R G B separated by space) and use [TColor::CreateColorTableFromFile](https://root.cern/doc/master/classTColor.html#a8b075c0f885fe2e672b68d06ed966f6c) #include \<TStyle.h\> #include \<TFile.h\> #include \<TH2F.h\> void p3\_draw() { const int n = 6; Int\_t MyPalette[n]; Int\_t FI = TColor::CreateColorTableFromFile("mycolours.txt"); for (int i = 0; i \< n; i++) MyPalette[i] = FI + i; gStyle-\>SetPalette(n, MyPalette); gStyle-\>SetNumberContours(n); gStyle-\>SetOptStat(0); TH2F\* h2 = …

---

<div class="post-metadata">

**Author:** ![dondo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dondo](https://root-forum.cern.ch/u/dondo)\
**Post date:** [September 1, 2025, 8:59am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/6 "2025-09-01T08:59:34Z")

</div>

Hi @linev and @dastudillo ,

thanks for both your suggestions.

```javascript
hist.SetBit(1024, true);

```

does the trick and fixes first two color issue. Maybe Sergey can explain what does it set exactly and it may be also the solution for the problem @dastudillo solved in the plain ROOT (but it may not work for custom palette, since I am using predefined one).

Best,

Dominik

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [September 1, 2025, 9:11am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/7 "2025-09-01T09:11:38Z")

</div>

> [@dondo](#):
>
> does the trick and fixes first two color issue

It is `kUserContour` bit of histogram.

So you need to set it to enable usage of custom contour levels.

And wrong two first colors on color palette I will fix separatly.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [September 5, 2025, 5:25am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/8 "2025-09-05T05:25:27Z")

</div>

> [@dondo](#):
>
> i do not understand why first two colors (blue) are the same

This was bug, which will be fixed in the next JSROOT version.

> <https://github.com/root-project/jsroot/issues/365>
>
> Found in https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090
> 
> Two first …rect drawn with same color. 
> Also normal colz drawing shows same problem
> Need to be checked.

Thanks to point out the problem!

---

<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:** [September 19, 2025, 5:26am UTC](https://root-forum.cern.ch/t/custom-palette-in-jsroot/64090/9 "2025-09-19T05:26:03Z")

</div>

Closed on September 19, 2025, 5:26am UTC

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