ROOT
master
Reference Guide
Loading...
Searching...
No Matches
hist010_TH1_two_scales.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
import
ROOT
14
import
numpy
as
np
15
16
c1 =
ROOT.TCanvas
(
"c1"
,
"hists with different scales"
,600,400)
17
18
ROOT.gStyle.SetOptStat
(
False
)
19
20
h1 =
ROOT.TH1F
(
"h1"
,
"my histogram"
,100,-3,3)
21
22
h1.Fill
(
np.array
([
ROOT.gRandom.Gaus
(0, 1)
for
_
in
range
(10000)]))
23
24
h1.Draw
()
25
c1.Update
()
26
27
hint1 =
ROOT.TH1F
(
"hint1"
,
"h1 bins integral"
,100,-3,3)
28
29
sum = 0
30
for
i
in
range
(1,101) :
31
sum +=
h1.GetBinContent
(i)
32
hint1.SetBinContent
(i,sum)
33
34
rightmax = 1.1*
hint1.GetMaximum
()
35
scale =
ROOT.gPad.GetUymax
()/rightmax
36
hint1.SetLineColor
(
"kRed"
)
37
hint1.Scale
(scale)
38
hint1.Draw
(
"same"
)
39
40
axis =
ROOT.TGaxis
(
ROOT.gPad.GetUxmax
(),
ROOT.gPad.GetUymin
(),
41
ROOT.gPad.GetUxmax
(),
ROOT.gPad.GetUymax
(),0,rightmax,510,
"+L"
)
42
axis.SetLineColor
(
"kRed"
)
43
axis.SetLabelColor
(
"kRed"
)
44
axis.Draw
()
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
tutorials
hist
hist010_TH1_two_scales.py
ROOT master - Reference Guide Generated on Thu Feb 13 2025 15:59:18 (GVA Time) using Doxygen 1.10.0