Logo ROOT   6.12/07
Reference Guide
twoscales.py
Go to the documentation of this file.
1 ## \file
2 ## \ingroup tutorial_hist
3 ## \notebook
4 ## Example of macro illustrating how to superimpose two histograms
5 ## with different scales in the "same" pad.
6 ## Inspired by work of Rene Brun.
7 ##
8 ## \macro_image
9 ## \macro_code
10 ##
11 ## \author Alberto Ferro
12 
13 #include "TCanvas.h"
14 #include "TStyle.h"
15 #include "TH1.h"
16 #include "TGaxis.h"
17 #include "TRandom.h"
18 
19 import ROOT
20 
21 c1 = ROOT.TCanvas("c1","hists with different scales",600,400)
22 
23 ROOT.gStyle.SetOptStat(False)
24 
25 h1 = ROOT.TH1F("h1","my histogram",100,-3,3)
26 
27 for i in range(10000) :
28  h1.Fill(ROOT.gRandom.Gaus(0,1))
29 
30 h1.Draw()
31 
32 hint1 = ROOT.TH1F("hint1","h1 bins integral",100,-3,3)
33 
34 sum = 0
35 for i in range(1,101) :
36  sum += h1.GetBinContent(i)
37  hint1.SetBinContent(i,sum)
38 
39 rightmax = 1.1*hint1.GetMaximum();
40 scale = ROOT.gPad.GetUymax()/rightmax;
41 hint1.SetLineColor(ROOT.kRed)
42 hint1.Scale(scale)
43 hint1.Draw("same")
44 
45 axis = ROOT.TGaxis(ROOT.gPad.GetUxmax(),ROOT.gPad.GetUymin(),
46  ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymax(),0,rightmax,510,"+L")
47 axis.SetLineColor(ROOT.kRed)
48 axis.SetLabelColor(ROOT.kRed)
49 axis.Draw()