Logo ROOT   6.12/06
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Namespaces
twoscales.py File Reference

Namespaces

 twoscales
 

Detailed Description

Example of macro illustrating how to superimpose two histograms with different scales in the "same" pad.

Inspired by work of Rene Brun.

pict1_twoscales.py.png
1 
2 #include "TCanvas.h"
3 #include "TStyle.h"
4 #include "TH1.h"
5 #include "TGaxis.h"
6 #include "TRandom.h"
7 
8 import ROOT
9 
10 c1 = ROOT.TCanvas("c1","hists with different scales",600,400)
11 
12 ROOT.gStyle.SetOptStat(False)
13 
14 h1 = ROOT.TH1F("h1","my histogram",100,-3,3)
15 
16 for i in range(10000) :
17  h1.Fill(ROOT.gRandom.Gaus(0,1))
18 
19 h1.Draw()
20 
21 hint1 = ROOT.TH1F("hint1","h1 bins integral",100,-3,3)
22 
23 sum = 0
24 for i in range(1,101) :
25  sum += h1.GetBinContent(i)
26  hint1.SetBinContent(i,sum)
27 
28 rightmax = 1.1*hint1.GetMaximum();
29 scale = ROOT.gPad.GetUymax()/rightmax;
30 hint1.SetLineColor(ROOT.kRed)
31 hint1.Scale(scale)
32 hint1.Draw("same")
33 
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)
38 axis.Draw()
Author
Alberto Ferro

Definition in file twoscales.py.