TRatioPlot->GetUpperRefYaxis()->SetMaxDigits()

I have a TRatioPlot and I would like to limit the number of digits on the axis of the upper plot, but it doesn’t seem to be possible. I’ve tried both rp->GetUpperRefYaxis()->SetMaxDigits(3) and h1->GetYaxis()->SetMaxDigits(3) but neither of these works.

Is there a workaround? Is this something that could be implemented in an updated ROOT version?

Thanks in advance

Maybe @couet can help with this

Do you have a small example reproducing your problem? What you are doing seems fine to me.

void MWE(){

  gStyle->SetOptStat(1110);
  gStyle->SetOptFit(0001);
  
  gStyle->SetOptStat(0);
  gStyle->SetOptFit();

  TRandom3 *myRNG=new TRandom3();
  myRNG->SetSeed(1);

  TH1F* h1 = new TH1F("h","h",500,200,700);
  TH1F* h2 = new TH1F("h2","h2",500,200,700);
  
  for (int ii=0;ii<1000000;ii++) {
    double rand = myRNG->Gaus(440,40);
    double rand2 = myRNG->Gaus(440,40);
    double rand3 = myRNG->Gaus(1,0.5);
    h1->Fill(rand);
    h2->Fill(rand2*rand3);
  }
  
  TCanvas* c1 = new TCanvas("c1","c1",900,700);
  TRatioPlot *rp = new TRatioPlot(h1,h2);
  rp->Draw();
  //  h2->GetYaxis()->SetMaxDigits(2);
  rp->GetUpperRefYaxis()->SetMaxDigits(2);
}

I am not sure why this does not work on this particular axis. One can change the title though … It would need to be investigated. Meanhwile you can do: TGaxis::SetMaxDigits(2);

Thank you, putting that line before the rest of my code works.

Yes, but all the axis will get that setting. I am now instigating why it does not work when you set it on the individual axis only.

1 Like

Indeed you used the wrong axis. You should do:

   rp->GetUpYaxis()->SetMaxDigits(4);
1 Like

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