Hi,
I translated the sample code for “Superimposing two histograms with different scales in the same pad” given in root.cern.ch/root/html/THistPainter.html to the piece of Python code shown below.
The C version works exactly as expected, the Python code creates just an empty frame with a nice title.
What did I do wrong in Python?
Thanks & regards,
Roland
[code]import ROOT
from ROOT import TCanvas, TNtuple, TH1F, TH2F, TF1, TLegend, TFile, TTree, THStack
from ROOT import TLatex, TAxis, TPaveText, TGaxis
from ROOT import gROOT, gSystem, gStyle, gPad, gEnv, gRandom
def superTest():
c1 = TCanvas(“c1”,“c1”,600,400)
create/fill draw h1
-------------------
gStyle.SetOptStat(ROOT.kFALSE)
h1 = TH1F(“h1”,“Superimposing two histograms with different scales”,100,-3,3)
for i in range(10000):
h1.Fill(gRandom.Gaus(0,1))
h1.Draw()
c1.Update()
create hint1 filled with the bins integral of h1
------------------------------------------------
hint1 = TH1F(“hint1”,“h1 bins integral”,100,-3,3)
sum = 0.0;
for i in range(100):
sum = sum + h1.GetBinContent(i)
hint1.SetBinContent(i,sum)
scale hint1 to the pad coordinates
----------------------------------
rightmax = 1.1*hint1.GetMaximum()
scale = gPad.GetUymax()/rightmax
hint1.SetLineColor(ROOT.kRed)
hint1.Scale(scale)
hint1.Draw(“same”)
draw an axis on the right side
------------------------------
axis = TGaxis(gPad.GetUxmax(), gPad.GetUymin(),
gPad.GetUxmax(), gPad.GetUymax(),0,rightmax,510,"+L")
axis.SetLineColor(ROOT.kRed)
axis.SetTextColor(ROOT.kRed)
axis.Draw()
return c1
superTest().Print(‘super.png’)[/code]