Logo ROOT   6.12/07
Reference Guide
graph.py
Go to the documentation of this file.
1 ## \file
2 ## \ingroup tutorial_pyroot
3 ## \notebook
4 ## A Simple Graph Example
5 ##
6 ## \macro_image
7 ## \macro_output
8 ## \macro_code
9 ##
10 ## \author Wim Lavrijsen
11 
12 from __future__ import print_function
13 from ROOT import TCanvas, TGraph
14 from ROOT import gROOT
15 from math import sin
16 from array import array
17 
18 
19 c1 = TCanvas( 'c1', 'A Simple Graph Example', 200, 10, 700, 500 )
20 
21 c1.SetFillColor( 42 )
22 c1.SetGrid()
23 
24 n = 20
25 x, y = array( 'd' ), array( 'd' )
26 
27 for i in range( n ):
28  x.append( 0.1*i )
29  y.append( 10*sin( x[i]+0.2 ) )
30  print(' i %i %f %f ' % (i,x[i],y[i]))
31 
32 gr = TGraph( n, x, y )
33 gr.SetLineColor( 2 )
34 gr.SetLineWidth( 4 )
35 gr.SetMarkerColor( 4 )
36 gr.SetMarkerStyle( 21 )
37 gr.SetTitle( 'a simple graph' )
38 gr.GetXaxis().SetTitle( 'X title' )
39 gr.GetYaxis().SetTitle( 'Y title' )
40 gr.Draw( 'ACP' )
41 
42 # TCanvas.Update() draws the frame, after which one can change it
43 c1.Update()
44 c1.GetFrame().SetFillColor( 21 )
45 c1.GetFrame().SetBorderSize( 12 )
46 c1.Modified()
47 c1.Update()
double sin(double)
c SetBorderSize(2)
h1 SetFillColor(kGreen)
The Canvas class.
Definition: TCanvas.h:31
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41