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 __future__ import print_function
13from ROOT import TCanvas, TGraph
14from ROOT import gROOT
15from math import sin
16from array import array
17
18
19c1 = TCanvas( 'c1', 'A Simple Graph Example', 200, 10, 700, 500 )
20
21c1.SetFillColor( 42 )
22c1.SetGrid()
23
24n = 20
25x, y = array( 'd' ), array( 'd' )
26
27for 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
32gr = TGraph( n, x, y )
33gr.SetLineColor( 2 )
34gr.SetLineWidth( 4 )
35gr.SetMarkerColor( 4 )
36gr.SetMarkerStyle( 21 )
37gr.SetTitle( 'a simple graph' )
38gr.GetXaxis().SetTitle( 'X title' )
39gr.GetYaxis().SetTitle( 'Y title' )
40gr.Draw( 'ACP' )
41
42# TCanvas.Update() draws the frame, after which one can change it
43c1.Update()
44c1.GetFrame().SetFillColor( 21 )
45c1.GetFrame().SetBorderSize( 12 )
46c1.Modified()
47c1.Update()
48# If the graph does not appear, try using the "i" flag, e.g. "python3 -i graph.py"
49# This will access the interactive mode after executing the script, and thereby persist
50# 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)