Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist010_TH1_two_scales.py File Reference

Detailed Description

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

Inspired by work of Rene Brun.

import ROOT
import numpy as np
c1 = ROOT.TCanvas("c1","hists with different scales",600,400)
h1 = ROOT.TH1F("h1","my histogram",100,-3,3)
h1.Fill(np.array([ROOT.gRandom.Gaus(0, 1) for _ in range(10000)]))
hint1 = ROOT.TH1F("hint1","h1 bins integral",100,-3,3)
sum = 0
for i in range(1,101) :
sum += h1.GetBinContent(i)
rightmax = 1.1*hint1.GetMaximum()
scale = ROOT.gPad.GetUymax()/rightmax
hint1.Draw("same")
ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymax(),0,rightmax,510,"+L")
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Author
Alberto Ferro

Definition in file hist010_TH1_two_scales.py.