I am plotting a TH2 with log scale on Z axis in the following way:
Now, what I would like to do is taking the color of the Z axis and use them in other part of the code. My strategy in this moment is to pick up the palette and use GetValueColor:
auto* palette = dynamic_cast<TPaletteAxis*>(h_vals->GetListOfFunctions()->FindObject("palette"));
// first for main cell value histogram
double binc = h_vals->GetBinContent(get_bin_number(this_bin));
Int_t color_id = palette->GetValueColor(binc);
This does not work as expected, as you can see in the following plot
example_Log.pdf (25.0 KB)
Do you have any suggestions on how to fix it or test the problem in a better way?
ROOT Version: 6.06.06
Does it work if you do not set the log scale along Z ?
Yes, here the result
example.pdf (23.3 KB)
I tried to reproduce it and I see there is a problem in log Z
root  hpxpy->Draw("COLZ");
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root  gPad->SetLogz()
root  TPaletteAxis *palette = (TPaletteAxis*)hpxpy->GetListOfFunctions()->FindObject("palette");
root  Int_t ci = palette->GetValueColor(1.);
root  TColor *c = gROOT->GetColor(ci);
root  float r,g,b;
root  c->GetRGB(r,g,b);
root  r
root  g
root  b
root  ci
root  gPad->SetFillColor(1076)
I asked color for 1 and it seems more like the one for 10
I found a workaround. If you take the log of the value you want find the color for ,then it is ok. In my example it would be:
Int_t ci = palette->GetValueColor(TMath::Log10(1.));
This seems a nice workaround.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.