Display two histograms and their ratio.
This program illustrates how to plot two histograms and their ratio on the same canvas. Original macro by Olivier Couet.
2 from ROOT
import TCanvas, TColor, TGaxis, TH1F, TPad
3 from ROOT
import kBlack, kBlue, kRed
7 h1 =
TH1F(
"h1", (
"Two gaussian plots and their ratio; x title; h1 and h2" 8 " histograms"), 100, -5, 5)
9 h1.SetLineColor(kBlue+1)
12 h1.GetYaxis().SetTitleSize(20)
13 h1.GetYaxis().SetTitleFont(43)
14 h1.GetYaxis().SetTitleOffset(1.55)
20 h2 =
TH1F(
"h2",
"h2", 100, -5, 5)
27 def createRatio(h1, h2):
29 h3.SetLineColor(kBlack)
41 y.SetTitle(
"ratio h1/h2 ")
45 y.SetTitleOffset(1.55)
60 def createCanvasPads():
61 c =
TCanvas(
"c",
"canvas", 800, 800)
63 pad1 =
TPad(
"pad1",
"pad1", 0, 0.3, 1, 1.0)
64 pad1.SetBottomMargin(0)
69 pad2 =
TPad(
"pad2",
"pad2", 0, 0.05, 1, 0.3)
71 pad2.SetBottomMargin(0.2)
82 h3 = createRatio(h1, h2)
83 c, pad1, pad2 = createCanvasPads()
90 h1.GetYaxis().SetLabelSize(0.0)
91 axis =
TGaxis(-5, 20, -5, 220, 20, 220, 510,
"")
102 if __name__ ==
"__main__":
- Author
- Michael Moran
Definition in file ratioplot.py.