Axes labels in TRatioPlot are partially out of the canvas if their size is too large

Hello,

I’m having what I think is a simple problem with TRatioPlot. If I set the TitleSize of the three axes (Upper and Lower y axis; Lower x axis) too large, the labels are partially cut out of the final plot. That is: I need to tell TRatioPlot to increase the canvas/pad sizes to accommodate the larger sized titles.

I tried a lot of options but couldn’t get it to work.

I attach a self contained python3 script which will reproduce the problem.
In the script titlesize=0.06 leads to titles outside of the canvas while titlesize=0.04 seems fine.

I know one can fudge with offsets (in the actual plot I’m trying to generate this is not enough) but I’d like to understand how to increase the size of the canvas/pad itself.

Thanks!
Enrico

Example:

#!/opt/homebrew/bin/python3
import sys, os, shutil
import ROOT as ROOT
from ROOT import *
ROOT.gStyle.SetOptStat(111110)
ROOT.gROOT.SetBatch(kTRUE)
ROOT.gStyle.SetTitleFontSize(0.08)

titlesize = 0.06

c1 = ROOT.TCanvas(“c1”,“c1”)

h1 = ROOT.TH1F(‘h1’,‘h1_name’,100,-3,3)
h1.FillRandom(“gaus”, 200000)
h1.Scale(1.0/h1.Integral(), “width”)
h1.SetLineColor(kRed)
h1.SetStats(False)
h1.GetXaxis().SetRangeUser(-3,3)
h1.GetYaxis().SetRangeUser(0,0.5)
h1.SetTitle(“TITLE”)
h1.SetXTitle(“xtitle”)

h2 = ROOT.TH1F(‘h2’,‘h2_name’,100,-3,3)
h2.FillRandom(“gaus”, 200000)
h2.Scale(1.0/h2.Integral(), “width”)
h2.SetLineColor(kBlue)

rp = TRatioPlot(h1, h2)
rp.SetH1DrawOpt(“HIST E”)
rp.Draw()
rp.GetLowerRefGraph().SetMinimum (0.5)
rp.GetLowerRefGraph().SetMaximum (1.5)
rp.GetUpperRefYaxis().SetTitle(“upper”)
rp.GetLowerRefYaxis().SetTitle(“lower”)

if titlesize is too large it is cut out of the canvas

rp.GetUpperRefYaxis().SetTitleSize(titlesize)
rp.GetLowerRefYaxis().SetTitleSize(titlesize)
rp.GetLowerRefXaxis().SetTitleSize(titlesize)

gPad.Update()
c1.Print(“test_ratioplot.pdf”)

_ROOT Version:6.26/06
_Platform: MacOS
_Compiler: python3

test_ratioplot.pdf (29.2 KB)

2 solutions: 1) enlarge the left and bottom margins 2) reduce the titles offsets.

Dear Olivier,
I swear that I had tried to use SetLowBottomMargin and it didn’t work (I still have the option commented in the actual code). When I tried again now … it works. Somehow in the fury of different options I tried I must have had conflicting settings. This is embarrassing.

Thanks for the help!
Enrico

1 Like

Dear Oliver,
as a follow-up, I noticed that changing margins and or offsets doesn’t change the aspect-ratio of the plot. For instance, the difference between the two attached plots is that in the compressed one I set SetLowBottomMargin.

You see that the label comes into view but at the expense of the lower plot which ends up compressed.

Is it possible to preserve the two plots and instead increase the size of the canvas (i.e. changing the aspect-ratio of the plot)?

Best,
Enrico

test_ratioplot.pdf (29.0 KB)
test_ratioplot_compressed.pdf (28.9 KB)

Finally I found how control everything. I report it here in case some other root-amateur is in need.

The aspect ratio is controlled by the canvas:
c1 = ROOT.TCanvas(“c1”,“c1”,width,height)

The vertical point at which the main pad is split is controlled by SetSplitFraction which is 0.3 by default.
rp = TRatioPlot(h1,h2)
rp.SetSplitFraction(0.4) # to set it at 40%

The plots inside the upper/lower pads can be moved around using
SetUpBottomMargin, SetUpTopMargin (for the upper pad)
SetLowBottomMargin, SetLowTopMargin (for the lower pad)
SetLeftMargin and SetRightMargin (both pads)

The separation between the plots is also controlled by SetSeparationMargin

The axes titles can be also moved around with various offsets.
e.g.
rp.GetLowerRefXaxis().SetTitleOffset(0.5)
etc…

Best,
Enrico

1 Like

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