SetNdivisions in TRatioPlot lower pad

Dear Rooters,

I’m trying to change the number of divisions in the lower pad of a TRatioPlot().

Here is an example of what I want to do in PyROOT:

import ROOT

h1 = ROOT.TH1D('h1','h1',21,-5,5)
h2 = ROOT.TH1D('h2','h2',21,-5,5)
h1.FillRandom('gaus',10000)
h2.FillRandom('gaus',10000)

c = ROOT.TCanvas()

r = ROOT.TRatioPlot(h1, h2)
r.Draw()

r.GetLowerRefYaxis().SetNdivisions(2, True)
r.GetLowerRefYaxis().SetRangeUser(0, 2)

c.Draw()

Here is the output from the code above:

As you can see, the range on the lower pad has been set as specified by SetRangeUser. But the SetNdivisions method does not seem to have been applied. Also, calling r.GetLowerPad().Update() or c.Update() does not seem to do anything.

Is there a workaround to change the number of divisions on the lower pad?

IMO the behaviour of SetNdivisions should be the same as for SetRangeUser above. It should be easy to change the number of axis divisions to avoid overlapping axis labels as in the plot above.

Cheers,
Alex


ROOT Version: 6.30


{
   auto C  = new TCanvas("C", "A ratio example");

   auto h1 = new TH1D("h1","h1",21,-5,5);
   auto h2 = new TH1D("h2","h2",21,-5,5);

   h1->FillRandom("gaus",10000);
   h2->FillRandom("gaus",10000);

   auto r = new TRatioPlot(h1, h2);
   r->Draw();

    r->GetLowYaxis()->SetNdivisions(2);
    r->GetLowerRefYaxis()->SetRangeUser(0, 2);
}

Hi Olivier,

Thanks for the speedy reply!

The code does indeed seem to work in Cint. It’s only in pyROOT where the behaviour isn’t as expected. I did manage to get it to work by JITing a wrapper function:

import ROOT

ROOT.gInterpreter.Declare("""
void TRatioPlotLowerSetNdivisions( TRatioPlot* r, uint ndiv, bool opti ){
   r->GetLowYaxis()->SetNdivisions(ndiv,opti);
};
""")

c = ROOT.TCanvas()

h1 = ROOT.TH1D('h1','h1',21,-5,5)
h2 = ROOT.TH1D('h2','h2',21,-5,5)
h1.FillRandom('gaus',10000)
h2.FillRandom('gaus',10000)

r = ROOT.TRatioPlot( h1, h2 )
r.Draw()
ROOT.TRatioPlotLowerSetNdivisions( r, 2, True )
r.GetLowerRefYaxis().SetRangeUser(0,2)

c.Draw()

Still puzzled as to why the code above doesn’t have the same effect. Hope this will get fixed in the future.

Yes or the divisions you need to use GetLowYaxis

Aha, so there is a different behaviour for GetLowYaxis and GetLowerRefYaxis. Got it.

Although, it seems far from obvious that these methods don’t point to the same object.

Cheers,
Alex

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