Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
h1ReadAndDraw.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
12import ROOT
13from ROOT import TCanvas, TPad, TFile, TPaveLabel, TPaveText
14from ROOT import gROOT
15
16c1 = TCanvas( 'c1', 'Histogram Drawing Options', 200, 10, 700, 900 )
17
18pad1 = TPad( 'pad1', 'The pad with the function', 0.03, 0.62, 0.50, 0.92, 21 )
19pad2 = TPad( 'pad2', 'The pad with the histogram', 0.51, 0.62, 0.98, 0.92, 21 )
20pad3 = TPad( 'pad3', 'The pad with the histogram', 0.03, 0.02, 0.97, 0.57, 21 )
21pad1.Draw()
22pad2.Draw()
23pad3.Draw()
24#
25# We connect the ROOT file generated in a previous tutorial
26#
27File = "py-hsimple.root"
28if (ROOT.gSystem.AccessPathName(File)) :
29 ROOT.Info("h1ReadAndDraw.py", File+" does not exist")
30 exit()
31
32example = TFile(File)
33example.ls()
34
35# Draw a global picture title
36title = TPaveLabel( 0.1, 0.94, 0.9, 0.98,
37 'Drawing options for one dimensional histograms' )
38title.SetFillColor( 16 )
39title.SetTextFont( 52 )
40title.Draw()
41#
42# Draw histogram hpx in first pad with the default option.
43pad1.cd()
44pad1.GetFrame().SetFillColor( 18 )
45hpx = gROOT.FindObject( 'hpx' )
46hpx.SetFillColor( 45 )
47hpx.DrawCopy()
48label1 = TPaveLabel( -3.5, 700, -1, 800, 'Default option' )
49label1.SetFillColor( 42 )
50label1.Draw()
51#
52# Draw hpx as a lego. Clicking on the lego area will show
53# a "transparent cube" to guide you rotating the lego in real time.
54pad2.cd()
55hpx.DrawCopy( 'lego1' )
56label2 = TPaveLabel( -0.72, 0.74, -0.22, 0.88, 'option Lego1' )
57label2.SetFillColor( 42 )
58label2.Draw()
59label2a = TPaveLabel( -0.93, -1.08, 0.25, -0.92, 'Click on lego to rotate' )
60label2a.SetFillColor( 42 )
61label2a.Draw()
62#
63# Draw hpx with its errors and a marker.
64pad3.cd()
65pad3.SetGridx()
66pad3.SetGridy()
67pad3.GetFrame().SetFillColor( 18 )
68hpx.SetMarkerStyle( 21 )
69hpx.Draw( 'e1p' )
70label3 = TPaveLabel( 2, 600, 3.5, 650, 'option e1p' )
71label3.SetFillColor( 42 )
72label3.Draw()
73#
74# The following illustrates how to add comments using a PaveText.
75# Attributes of text/lines/boxes added to a PaveText can be modified.
76# The AddText function returns a pointer to the added object.
77pave = TPaveText( -3.78, 500, -1.2, 750 )
78pave.SetFillColor( 42 )
79t1 = pave.AddText( 'You can move' )
80t1.SetTextColor( 4 )
81t1.SetTextSize( 0.05 )
82pave.AddText( 'Title and Stats pads' )
83pave.AddText( 'X and Y axis' )
84pave.AddText( 'You can modify bin contents' )
85pave.Draw()
86c1.Update()
Option_t Option_t SetFillColor
The Canvas class.
Definition TCanvas.h:23
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
The most important graphics class in the ROOT system.
Definition TPad.h:28
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21