Logo ROOT   6.14/05
Reference Guide
h1draw.py
Go to the documentation of this file.
1 ## \file
2 ## \ingroup tutorial_pyroot
3 ## \notebook -js
4 ## A Simple histogram drawing example
5 ##
6 ## \macro_image
7 ## \macro_output
8 ## \macro_code
9 ##
10 ## \author Wim Lavrijsen
11 
12 from ROOT import TCanvas, TPad, TFile, TPaveLabel, TPaveText
13 from ROOT import gROOT
14 
15 c1 = TCanvas( 'c1', 'Histogram Drawing Options', 200, 10, 700, 900 )
16 
17 pad1 = TPad( 'pad1', 'The pad with the function', 0.03, 0.62, 0.50, 0.92, 21 )
18 pad2 = TPad( 'pad2', 'The pad with the histogram', 0.51, 0.62, 0.98, 0.92, 21 )
19 pad3 = TPad( 'pad3', 'The pad with the histogram', 0.03, 0.02, 0.97, 0.57, 21 )
20 pad1.Draw()
21 pad2.Draw()
22 pad3.Draw()
23 #
24 # We connect the ROOT file generated in a previous tutorial
25 #
26 example = TFile( 'py-hsimple.root' )
27 example.ls()
28 
29 # Draw a global picture title
30 title = TPaveLabel( 0.1, 0.94, 0.9, 0.98,
31  'Drawing options for one dimensional histograms' )
32 title.SetFillColor( 16 )
33 title.SetTextFont( 52 )
34 title.Draw()
35 #
36 # Draw histogram hpx in first pad with the default option.
37 pad1.cd()
38 pad1.GetFrame().SetFillColor( 18 )
39 hpx = gROOT.FindObject( 'hpx' )
40 hpx.SetFillColor( 45 )
41 hpx.DrawCopy()
42 label1 = TPaveLabel( -3.5, 700, -1, 800, 'Default option' )
43 label1.SetFillColor( 42 )
44 label1.Draw()
45 #
46 # Draw hpx as a lego. Clicking on the lego area will show
47 # a "transparent cube" to guide you rotating the lego in real time.
48 pad2.cd()
49 hpx.DrawCopy( 'lego1' )
50 label2 = TPaveLabel( -0.72, 0.74, -0.22, 0.88, 'option Lego1' )
51 label2.SetFillColor( 42 )
52 label2.Draw()
53 label2a = TPaveLabel( -0.93, -1.08, 0.25, -0.92, 'Click on lego to rotate' )
54 label2a.SetFillColor( 42 )
55 label2a.Draw()
56 #
57 # Draw hpx with its errors and a marker.
58 pad3.cd()
59 pad3.SetGridx()
60 pad3.SetGridy()
61 pad3.GetFrame().SetFillColor( 18 )
62 hpx.SetMarkerStyle( 21 )
63 hpx.Draw( 'e1p' )
64 label3 = TPaveLabel( 2, 600, 3.5, 650, 'option e1p' )
65 label3.SetFillColor( 42 )
66 label3.Draw()
67 #
68 # The following illustrates how to add comments using a PaveText.
69 # Attributes of text/lines/boxes added to a PaveText can be modified.
70 # The AddText function returns a pointer to the added object.
71 pave = TPaveText( -3.78, 500, -1.2, 750 )
72 pave.SetFillColor( 42 )
73 t1 = pave.AddText( 'You can move' )
74 t1.SetTextColor( 4 )
75 t1.SetTextSize( 0.05 )
76 pave.AddText( 'Title and Stats pads' )
77 pave.AddText( 'X and Y axis' )
78 pave.AddText( 'You can modify bin contents' )
79 pave.Draw()
80 c1.Update()
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:20
h1 SetFillColor(kGreen)
The most important graphics class in the ROOT system.
Definition: TPad.h:29
The Canvas class.
Definition: TCanvas.h:31
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21