ROOT
Version v6.34
master
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
timeSeriesFromCSV.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_graphs
3
## \notebook -js
4
## This macro illustrates the use of the time axis on a TGraph
5
## with data read from a text file containing the SWAN usage
6
## statistics during July 2017.
7
##
8
## \macro_image
9
## \macro_code
10
##
11
## \authors Danilo Piparo, Olivier Couet
12
13
import
ROOT
14
15
# Open the data file. This csv contains the usage statistics of a CERN IT
16
# service, SWAN, during two weeks. We would like to plot this data with
17
# ROOT to draw some conclusions from it.
18
dirName = str(
ROOT.gROOT.GetTutorialDir
())
19
dirName +=
"/graphs/"
20
dirName=
dirName.replace
(
"/./"
,
"/"
)
21
inputFileName =
"%s/SWAN2017.dat"
%dirName
22
23
# Create the time graph
24
g =
ROOT.TGraph
()
25
g.SetTitle
(
"SWAN Users during July 2017;Time;Number of Sessions"
)
26
27
# Read the data and fill the graph with time along the X axis and number
28
# of users along the Y axis
29
30
lines = open(inputFileName,
"r"
).
readlines
()
31
32
for
i, line
in
enumerate
(lines):
33
d, h, value =
line.split
()
34
g.SetPoint
(i,
ROOT.TDatime
(
"%s %s"
%(d,h)).Convert(), float(value))
35
36
# Draw the graph
37
c =
ROOT.TCanvas
(
"c"
,
"c"
, 950, 500)
38
c.SetLeftMargin
(0.07)
39
c.SetRightMargin
(0.04)
40
c.SetGrid
()
41
g.SetLineWidth
(3)
42
g.SetLineColor
(
ROOT.kBlue
)
43
g.Draw
(
"al"
)
44
g.GetYaxis
().CenterTitle()
45
46
# Make the X axis labelled with time
47
xaxis =
g.GetXaxis
()
48
xaxis.SetTimeDisplay
(1)
49
xaxis.CenterTitle
()
50
xaxis.SetTimeFormat
(
"%a %d"
)
51
xaxis.SetTimeOffset
(0)
52
xaxis.SetNdivisions
(-219)
53
xaxis.SetLimits
(
ROOT.TDatime
(2017, 7, 3, 0, 0, 0).Convert(),
ROOT.TDatime
(2017, 7, 22, 0, 0, 0).Convert())
54
xaxis.SetLabelSize
(0.025)
55
xaxis.CenterLabels
()
56
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
tutorials
graphs
timeSeriesFromCSV.py
ROOT tags/6-34-04 - Reference Guide Generated on Thu Mar 27 2025 14:48:01 (GVA Time) using Doxygen 1.10.0