Hello all,
Hope you are well.
I was trying to make a plotting code that does multiple pads but I was having some trouble in scaling the titles and ticks correctly. I may have misunderstood that the sizes scale with the are of the pads themselves. I understand I can do pixel size for the text themselves although not sure if something similar exists for the ticks.
Would appreciate any ideas for the same.
Thank you in advanced.
import ROOT
ROOT.gROOT.SetBatch(True)
ROOT.gStyle.SetOptStat(0)
# Set up three pads (sometimes can be two)
c = ROOT.TCanvas()
pad1 = ROOT.TPad("pad1", "pad1", 0, 0.5, 1, 1)
pad2 = ROOT.TPad("pad2", "pad2", 0, 0.25, 1, 0.5)
pad3 = ROOT.TPad("pad3", "pad3", 0, 0, 1, 0.25)
pad1.SetBottomMargin(0)
pad2.SetTopMargin(0)
pad2.SetBottomMargin(0.3)
pad1.Draw()
pad2.Draw()
pad3.Draw()
c.Draw()
# Setup histograms
# h1, h2 go on pad1
h1 = ROOT.TH1D("h1", "h1", 10, 0, 10)
h2 = ROOT.TH1D("h2", "h2", 10, 0, 10)
h1.FillRandom("gaus", 1000)
h2.FillRandom("gaus", 1000)
# hR goes on pad2
hR = h1.Clone("hR")
hR.Divide(h2)
# hM goes on pad3
hM = h1.Clone("hM")
hM.Add(-1*h2)
hM.Divide(hR)
# Set axis label size correctly...
ylabelSize = 0.05
yTickSize = 0.02
xTickSize = 0.02
h1.GetYaxis().SetTitle("Events")
h1.GetYaxis().SetTitleSize(ylabelSize)
h1.GetYaxis().SetTickSize(yTickSize)
h1.GetXaxis().SetTickSize(xTickSize)
# Scaling Factor for pad2/pad3
pad1Area = pad1.GetWNDC() * pad1.GetHNDC()
pad2Area = pad2.GetWNDC() * pad2.GetHNDC()
pad3Area = pad3.GetWNDC() * pad3.GetHNDC()
pad2ScaleFactor = pad1Area / pad2Area
pad3ScaleFactor = pad1Area / pad3Area
# hR and hM axis label sizes consistent with pad1?
hR.GetYaxis().SetTitle("Ratio")
hR.GetYaxis().SetTitleSize(ylabelSize * pad2ScaleFactor)
hR.GetYaxis().SetTickSize(yTickSize * pad2ScaleFactor)
hR.GetXaxis().SetTickSize(xTickSize * pad2ScaleFactor)
hM.GetYaxis().SetTitle("Difference / Ratio")
hM.GetYaxis().SetTitleSize(ylabelSize * pad3ScaleFactor)
hM.GetYaxis().SetTickSize(yTickSize * pad3ScaleFactor)
hM.GetXaxis().SetTickSize(xTickSize * pad3ScaleFactor)
pad1.cd()
h1.SetLineColor(ROOT.kRed)
h1.Draw("hist")
h2.SetLineColor(ROOT.kBlue)
h2.Draw("hist same")
pad2.cd()
hR.SetLineColor(ROOT.kBlack)
hR.Draw("hist")
pad3.cd()
hM.SetLineColor(ROOT.kGreen)
hM.Draw("hist")
c.SaveAs("test.pdf")