Draw("colz") with more than 20 colors?

Hello ROOT experts,

I’m using the rainbow palette one obtains with gStyle->SetPalette(1). When I draw a 2D histogram with “colz”, I’d like to have a smooth transition between colors, instead of the 20 distinct ones I get now.

I even tried setting my own palette with 500 different colors, following the example in TColor.cxx. If I iterate over the list of colors and dump out their hues, I indeed see that all 500 are distinct. But, when I view/save the image, the colors still get binned into about 20. This is especially apparent if I save the file as a SVG and count the unique colors:

>>> set([y.split('fill="')[1].split('"')[0] for y in open('test.svg').readlines() if 'fill="' in y])
set(['#66ff00', '#ff3300', '#ffff00', '#ccff00', '#ff9900', '#ffcc00', '#0099ff', 'black', '#0066ff', '#00ff33', '#99ff00', '#00ffff', '#0033ff', '#ff6600', '#00ff99', '#33ff00', '#ff0000', 'white', 'none', '#00ff66', '#00ffcc', '#00ff00', '#00ccff'])
>>> len(_)

Is there some binning in the color (z) axis that needs to be increased to get what I want?

Test script attached. I’m using ROOT 5.22/00a as installed on lxplus.

colors.C (2.08 KB)

Here is an example creating a smooth palette:

   TCanvas *c  = new TCanvas("c","Contours",600,0,600,600);
   TF2 *f1 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);

   Int_t Number = 5;
   Double_t Red[Number] = { 0.00, 0.09, 0.18, 0.09, 0.00 };
   Double_t Green[Number] = { 0.01, 0.02, 0.39, 0.68, 0.97 };
   Double_t Blue[Number] = { 0.17, 0.39, 0.62, 0.79, 0.97 };
   Double_t Stops[Number] = { 0.00, 0.34, 0.61, 0.84, 1.00 };

   Int_t nb=80;

See also the HowTo here:
root.cern.ch/drupal/content/how- … or-palette

Apparently the key line is


as I had tried CreateGradientColorTable() before with the same results as my creating the palette manually.

Looking at TH1::SetContour, it is not immediately apparent that the number of contours also controls the number of colors, but the stated default of 20 agrees with the number of colors I was seeing. Perhaps the documentation could be improved to reflect this? Or perhaps a SetNumberOfColors(int nc)method could be added (it would simply call SetContour(nc), but would improve the “grammar” of the class)?

Just wanted to bump this thread so that perhaps the documentation would be improved.

I have improved the doc here:
I added a paragraph about SetContour. It will be visible as soon as the online documentation will be regenerated. Thanks for reporting this documentation weakness.