A Simple histogram drawing example.
TFile** py-hsimple.root Demo ROOT file with histograms
TFile* py-hsimple.root Demo ROOT file with histograms
KEY: TH1F hpx;1 This is the px distribution
KEY: TH2F hpxpy;1 py vs px
KEY: TProfile hprof;1 Profile of pz versus px
KEY: TNtuple ntuple;1 Demo ntuple
from ROOT import TCanvas, TPad, TFile, TPaveLabel, TPaveText
from ROOT import gROOT
c1 =
TCanvas(
'c1',
'Histogram Drawing Options', 200, 10, 700, 900 )
pad1 =
TPad(
'pad1',
'The pad with the function', 0.03, 0.62, 0.50, 0.92, 21 )
pad2 =
TPad(
'pad2',
'The pad with the histogram', 0.51, 0.62, 0.98, 0.92, 21 )
pad3 =
TPad(
'pad3',
'The pad with the histogram', 0.03, 0.02, 0.97, 0.57, 21 )
pad1.Draw()
pad2.Draw()
pad3.Draw()
example = TFile( 'py-hsimple.root' )
example.ls()
'Drawing options for one dimensional histograms' )
title.SetFillColor( 16 )
title.SetTextFont( 52 )
title.Draw()
pad1.cd()
hpx = gROOT.FindObject( 'hpx' )
hpx.SetFillColor( 45 )
hpx.DrawCopy()
label1 =
TPaveLabel( -3.5, 700, -1, 800,
'Default option' )
label1.SetFillColor( 42 )
label1.Draw()
pad2.cd()
hpx.DrawCopy( 'lego1' )
label2 =
TPaveLabel( -0.72, 0.74, -0.22, 0.88,
'option Lego1' )
label2.SetFillColor( 42 )
label2.Draw()
label2a =
TPaveLabel( -0.93, -1.08, 0.25, -0.92,
'Click on lego to rotate' )
label2a.SetFillColor( 42 )
label2a.Draw()
pad3.cd()
pad3.SetGridx()
pad3.SetGridy()
hpx.SetMarkerStyle( 21 )
hpx.Draw( 'e1p' )
label3 =
TPaveLabel( 2, 600, 3.5, 650,
'option e1p' )
label3.SetFillColor( 42 )
label3.Draw()
pave.SetFillColor( 42 )
t1 = pave.AddText( 'You can move' )
t1.SetTextColor( 4 )
t1.SetTextSize( 0.05 )
pave.AddText( 'Title and Stats pads' )
pave.AddText( 'X and Y axis' )
pave.AddText( 'You can modify bin contents' )
pave.Draw()
c1.Update()
- Author
- Wim Lavrijsen
Definition in file h1draw.py.