Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
gr108_timeSeriesFromCSV.py
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## \authors Danilo Piparo, Olivier Couet
11
12import ROOT
13
14# Open the data file. This csv contains the usage statistics of a CERN IT
15# service, SWAN, during two weeks. We would like to plot this data with
16# ROOT to draw some conclusions from it.
17dirName = str(ROOT.gROOT.GetTutorialDir())
18dirName += "/visualisation/graphs/"
19dirName= dirName.replace("/./", "/")
20inputFileName = "%s/SWAN2017.dat" %dirName
21
22# Create the time graph. In this example, we don't specify anything about it,
23# and data points will be added with SetPoint (the first point has index 0)
24g = ROOT.TGraph()
25g.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
30lines = open(inputFileName, "r").readlines()
31
32for 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
37c = ROOT.TCanvas("c", "c", 950, 500)
43g.Draw("al")
44g.GetYaxis().CenterTitle()
45
46# Make the X axis labelled with time
47xaxis = g.GetXaxis()
53xaxis.SetLimits(ROOT.TDatime(2017, 7, 3, 0, 0, 0).Convert(), ROOT.TDatime(2017, 7, 22, 0, 0, 0).Convert())
56
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.