Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Namespaces
h1draw.py File Reference

Namespaces

 h1draw
 

Detailed Description

A Simple histogram drawing example.

pict1_h1draw.py.png
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
1 
2 from ROOT import TCanvas, TPad, TFile, TPaveLabel, TPaveText
3 from ROOT import gROOT
4 
5 c1 = TCanvas( 'c1', 'Histogram Drawing Options', 200, 10, 700, 900 )
6 
7 pad1 = TPad( 'pad1', 'The pad with the function', 0.03, 0.62, 0.50, 0.92, 21 )
8 pad2 = TPad( 'pad2', 'The pad with the histogram', 0.51, 0.62, 0.98, 0.92, 21 )
9 pad3 = TPad( 'pad3', 'The pad with the histogram', 0.03, 0.02, 0.97, 0.57, 21 )
10 pad1.Draw()
11 pad2.Draw()
12 pad3.Draw()
13 #
14 # We connect the ROOT file generated in a previous tutorial
15 #
16 example = TFile( 'py-hsimple.root' )
17 example.ls()
18 
19 # Draw a global picture title
20 title = TPaveLabel( 0.1, 0.94, 0.9, 0.98,
21  'Drawing options for one dimensional histograms' )
22 title.SetFillColor( 16 )
23 title.SetTextFont( 52 )
24 title.Draw()
25 #
26 # Draw histogram hpx in first pad with the default option.
27 pad1.cd()
28 pad1.GetFrame().SetFillColor( 18 )
29 hpx = gROOT.FindObject( 'hpx' )
30 hpx.SetFillColor( 45 )
31 hpx.DrawCopy()
32 label1 = TPaveLabel( -3.5, 700, -1, 800, 'Default option' )
33 label1.SetFillColor( 42 )
34 label1.Draw()
35 #
36 # Draw hpx as a lego. Clicking on the lego area will show
37 # a "transparent cube" to guide you rotating the lego in real time.
38 pad2.cd()
39 hpx.DrawCopy( 'lego1' )
40 label2 = TPaveLabel( -0.72, 0.74, -0.22, 0.88, 'option Lego1' )
41 label2.SetFillColor( 42 )
42 label2.Draw()
43 label2a = TPaveLabel( -0.93, -1.08, 0.25, -0.92, 'Click on lego to rotate' )
44 label2a.SetFillColor( 42 )
45 label2a.Draw()
46 #
47 # Draw hpx with its errors and a marker.
48 pad3.cd()
49 pad3.SetGridx()
50 pad3.SetGridy()
51 pad3.GetFrame().SetFillColor( 18 )
52 hpx.SetMarkerStyle( 21 )
53 hpx.Draw( 'e1p' )
54 label3 = TPaveLabel( 2, 600, 3.5, 650, 'option e1p' )
55 label3.SetFillColor( 42 )
56 label3.Draw()
57 #
58 # The following illustrates how to add comments using a PaveText.
59 # Attributes of text/lines/boxes added to a PaveText can be modified.
60 # The AddText function returns a pointer to the added object.
61 pave = TPaveText( -3.78, 500, -1.2, 750 )
62 pave.SetFillColor( 42 )
63 t1 = pave.AddText( 'You can move' )
64 t1.SetTextColor( 4 )
65 t1.SetTextSize( 0.05 )
66 pave.AddText( 'Title and Stats pads' )
67 pave.AddText( 'X and Y axis' )
68 pave.AddText( 'You can modify bin contents' )
69 pave.Draw()
70 c1.Update()
Author
Wim Lavrijsen

Definition in file h1draw.py.