Custom palette in JSROOT

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:

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:

Thanks a lot for your suggestions and help.

Best,

Dominik

Hi Dominik,

Did you try to use “COL1“ draw option?

It introduced exactly for such purposes.

See ROOT: THistPainter Class Reference

Regards,

Sergey

Hello @linev ,

thanks, you are right, this is indeed the solution :slight_smile: . 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:

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

Yes, strange. I will investigate it.

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

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.

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):

Hi @linev and @dastudillo ,

thanks for both your suggestions.

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

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.

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

Thanks to point out the problem!