Label text formatting TH2F with COL TEXT option


ROOT Version: 5.34/34
Platform: Scientific Linux release 6.10
Compiler: gcc


Hi experts,
I’m currently trying to modify the text format of a TH2F TEXT label with gStyle->SetPaintTextFormat("1.1g"), this give me a correct behavior when numbers can be written in scientific notation as 1e-5 but for fewer exponents the numbers shows all the zeros, for example 3e-2=0.03 as you can see in the image. I want to have this labels written in scientific notation but keep the ones that are integers in normal notation.

Thank you
img.pdf (21.0 KB)

Can you post a small example reproducing the problem ?

# code block

void forum() 
{
  TH2F *h1 = new TH2F("h1","",20,-4,4,20,-20,20);
  TH2F *h2 = new TH2F("h2","",20,-4,4,20,-20,20);
  TH2F *hrate;

  Float_t px, py;
  for (Int_t i = 0; i < 25000; i++) 
    {
      gRandom->Rannor(px,py);
      h1->Fill(px,5*py);
    }
  for (Int_t i = 0; i < 1000; i++) 
    {
      gRandom->Rannor(px,py);
      h2->Fill(px,10*py);
    }

  hrate = (TH2F*)h2->Clone("rate");
  hrate->Divide(h1);

  TCanvas *c1 = new TCanvas("c1","c1");

  gStyle->SetHistMinimumZero();
  gStyle->SetPaintTextFormat("1.1g");
  
  hrate->Draw("COLZ TEXT");
}

This will give a 2D histogram with text labels img2.pdf (17.1 KB), what I want is to keep the style of the integer ones and give scientific notation to the other ones.

This can be work around with this post also, if the direct format doesn’t exist

with gStyle->SetPaintTextFormat the format is the same for all bins .

Yes…I was about to suggest you this

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