Example of macro illustrating how to superimpose two histograms with different scales in the "same" pad.
Inspired by work of Rene Brun.
10 c1 = ROOT.TCanvas(
"c1",
"hists with different scales",600,400)
12 ROOT.gStyle.SetOptStat(
False)
14 h1 = ROOT.TH1F(
"h1",
"my histogram",100,-3,3)
16 for i
in range(10000) :
17 h1.Fill(ROOT.gRandom.Gaus(0,1))
21 hint1 = ROOT.TH1F(
"hint1",
"h1 bins integral",100,-3,3)
24 for i
in range(1,101) :
25 sum += h1.GetBinContent(i)
26 hint1.SetBinContent(i,sum)
28 rightmax = 1.1*hint1.GetMaximum();
29 scale = ROOT.gPad.GetUymax()/rightmax;
30 hint1.SetLineColor(ROOT.kRed)
34 axis = ROOT.TGaxis(ROOT.gPad.GetUxmax(),ROOT.gPad.GetUymin(),
35 ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymax(),0,rightmax,510,
"+L")
36 axis.SetLineColor(ROOT.kRed)
37 axis.SetLabelColor(ROOT.kRed)
- Author
- Alberto Ferro
Definition in file twoscales.py.