Logo ROOT   6.12/06
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Namespaces
timeSeriesFromCSV.py File Reference

Namespaces

 timeSeriesFromCSV
 

Detailed Description

This macro illustrates the use of the time axis on a TGraph with data read from a text file containing the SWAN usage statistics during July 2017.

pict1_timeSeriesFromCSV.py.png
1 
2 import ROOT
3 
4 # Open the data file. This csv contains the usage statistics of a CERN IT
5 # service, SWAN, during two weeks. We would like to plot this data with
6 # ROOT to draw some conclusions from it.
7 dirName = str(ROOT.gROOT.GetTutorialDir())
8 dirName += "/graphs/"
9 dirName= dirName.replace("/./", "/")
10 inputFileName = "%s/SWAN2017.dat" %dirName
11 
12 # Create the time graph
13 g = ROOT.TGraph()
14 g.SetTitle("SWAN Users during July 2017;Time;Number of Sessions")
15 
16 # Read the data and fill the graph with time along the X axis and number
17 # of users along the Y axis
18 
19 lines = open(inputFileName, "r").readlines()
20 
21 for i, line in enumerate(lines):
22  d, h, value = line.split()
23  g.SetPoint(i, ROOT.TDatime("%s %s" %(d,h)).Convert(), float(value))
24 
25 # Draw the graph
26 c = ROOT.TCanvas("c", "c", 950, 500)
27 c.SetLeftMargin(0.07)
28 c.SetRightMargin(0.04)
29 c.SetGrid()
30 g.SetLineWidth(3)
31 g.SetLineColor(ROOT.kBlue)
32 g.Draw("al")
33 g.GetYaxis().CenterTitle()
34 
35 # Make the X axis labelled with time
36 xaxis = g.GetXaxis()
37 xaxis.SetTimeDisplay(1)
38 xaxis.CenterTitle()
39 xaxis.SetTimeFormat("%a %d")
40 xaxis.SetTimeOffset(0)
41 xaxis.SetNdivisions(-219)
42 xaxis.SetLimits(ROOT.TDatime(2017, 7, 3, 0, 0, 0).Convert(), ROOT.TDatime(2017, 7, 22, 0, 0, 0).Convert())
43 xaxis.SetLabelSize(0.025)
44 xaxis.CenterLabels()
45 
Authors
Danilo Piparo, Olivier Couet

Definition in file timeSeriesFromCSV.py.