ROOT
v6-32
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
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
()
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.
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
pyroot
graph.py
ROOT v6-32 - Reference Guide Generated on Mon Feb 3 2025 14:09:59 (GVA Time) using Doxygen 1.10.0