h3 has a bit higher maximum than the TRatioPlot upper pad Y axis range, so, let’s expand a bit that axis. But first of all one needs to know its current minimum and maximum:
ratio_plot.GetUpperPad().GetFrame().GetY2() returns the maximum of the lower TRatioPlot pad. ratio_plot.GetUpperRefYaxis().GetXmax()) returns 1 which is very crazy. ROOT.gPad.GetFrame().GetY2() again, returns the maximum of the lower TRatioPlot pad. ratio_plot.GetUpperPad().GetY2() returns some crazy numbers.
There is no way to use ratio_plot.GetUpperRefYaxis().SetRangeUser(some_min, some_max) without knowing the actual TRatioPlot upper pad Y axis range as hundreds of histograms are created automatically.
So, if the GetUpperPad().GetFrame().GetY2() does not work, how to know these values?
void ratioplot3() {
gStyle->SetOptStat(0);
auto c1 = new TCanvas("c1", "A ratio example");
auto h1 = new TH1D("h1", "h1", 50, 0, 10);
auto h2 = new TH1D("h2", "h2", 50, 0, 10);
auto f1 = new TF1("f1", "exp(- x/[0] )");
f1->SetParameter(0, 3);
h1->FillRandom("f1", 1900);
h2->FillRandom("f1", 2000);
h1->Sumw2();
h2->Scale(1.9 / 2.);
auto rp = new TRatioPlot(h1, h2);
rp->Draw();
c1->Update();
printf(">>> Maximum of the upper pad : %g\n",rp->GetUpperPad()->GetFrame()->GetY2());
}
Hi, thank you for the fast reply!
I translated your code to the Python version and it really works, but if you add c1.SetLogy(1) (or c1 -> SetLogy(1) to your macro) the results are getting weird. I forgot to add this to the first post.
#!/usr/bin/env python3
import ROOT
from ROOT import TCanvas, TRatioPlot, TF1
from ROOT import gStyle
ROOT.gStyle.SetOptStat(0)
c1 = ROOT.TCanvas("c1", "A ratio example")
c1.SetLogy(1)
h1 = ROOT.TH1D("h1", "h1", 50, 0, 10)
h2 = ROOT.TH1D("h2", "h2", 50, 0, 10)
f1 = ROOT.TF1("f1", "exp(- x/[0] )")
f1.SetParameter(0, 3)
h1.FillRandom("f1", 1900)
h2.FillRandom("f1", 2000)
h1.Sumw2();
h2.Scale(1.9 / 2.)
rp = ROOT.TRatioPlot(h1, h2)
rp.Draw()
c1.Update()
print(f'>>> Maximum of the upper pad : {rp.GetUpperPad().GetFrame().GetY2()}')
c1.Print('testrp.pdf')