Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
12from ROOT import TCanvas, TGraph
13from ROOT import gROOT
14from math import sin
15from array import array
16
17
18c1 = TCanvas( 'c1', 'A Simple Graph Example', 200, 10, 700, 500 )
19
20c1.SetFillColor( 42 )
21c1.SetGrid()
22
23n = 20
24x, y = array( 'd' ), array( 'd' )
25
26for i in range( n ):
27 x.append( 0.1*i )
28 y.append( 10*sin( x[i]+0.2 ) )
29 print(' i %i %f %f ' % (i,x[i],y[i]))
30
31gr = TGraph( n, x, y )
32gr.SetLineColor( 2 )
33gr.SetLineWidth( 4 )
34gr.SetMarkerColor( 4 )
35gr.SetMarkerStyle( 21 )
36gr.SetTitle( 'a simple graph' )
37gr.GetXaxis().SetTitle( 'X title' )
38gr.GetYaxis().SetTitle( 'Y title' )
39gr.Draw( 'ACP' )
40
41# TCanvas.Update() draws the frame, after which one can change it
42c1.Update()
43c1.GetFrame().SetFillColor( 21 )
44c1.GetFrame().SetBorderSize( 12 )
45c1.Modified()
46c1.Update()
47# If the graph does not appear, try using the "i" flag, e.g. "python3 -i graph.py"
48# This will access the interactive mode after executing the script, and thereby persist
49# long enough for the graph to appear.
Option_t Option_t SetFillColor
The Canvas class.
Definition TCanvas.h:23
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
c SetBorderSize(2)