ROOT
master
Reference Guide
Loading...
Searching...
No Matches
graph.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_graphs
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
ROOT
import
TCanvas, TGraph
13
from
ROOT
import
gROOT
14
from
math
import
sin
15
from
array
import
array
16
17
18
c1 =
TCanvas
(
'c1'
,
'A Simple Graph Example'
, 200, 10, 700, 500 )
19
20
c1.SetFillColor
( 42 )
21
c1.SetGrid
()
22
23
n = 20
24
x, y = array(
'd'
), array(
'd'
)
25
26
for
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
31
gr =
TGraph
( n, x, y )
32
gr.SetLineColor
( 2 )
33
gr.SetLineWidth
( 4 )
34
gr.SetMarkerColor
( 4 )
35
gr.SetMarkerStyle
( 21 )
36
gr.SetTitle
(
'a simple graph'
)
37
gr.GetXaxis
().SetTitle(
'X title'
)
38
gr.GetYaxis
().SetTitle(
'Y title'
)
39
gr.Draw
(
'ACP'
)
40
41
# TCanvas.Update() draws the frame, after which one can change it
42
c1.Update
()
43
c1.GetFrame
().
SetFillColor
( 21 )
44
c1.GetFrame
().
SetBorderSize
( 12 )
45
c1.Modified
()
46
c1.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.
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
SetFillColor
Option_t Option_t SetFillColor
Definition
TGWin32VirtualXProxy.cxx:50
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition
TGraph.h:41
SetBorderSize
c SetBorderSize(2)
tutorials
visualisation
graphs
graph.py
ROOT master - Reference Guide Generated on Wed Jan 15 2025 15:31:15 (GVA Time) using Doxygen 1.10.0