Dear all,
I would like to plot a second-based epoch timestamp from a csv file using RDataframe. Is there any simple method to do it? My code is the following:
Hi @Rigolo94 ,
I would say your code looks good, maybe one issue could be that timestamp points are plotted as integers on the graph.
This tutorial could help you. See how the timestamps are first converted to TDatime values and then are passed to the TGraph constructor.
Dear @vpadulan,
thanks for the hint. I got my code working by updating it in the following way:
import ROOT as rt
string = '''timestamp vmon
1559913959 4
1559913969 204
1559913979 454
1559913989 661'''
filename = 'test.csv'
canvas = rt.TCanvas("canvas", "canvas", 600, 600)
with open(filename, 'w') as f:
f.write(string)
MakeCsvDataFrame = rt.ROOT.RDF.MakeCsvDataFrame
rdf = MakeCsvDataFrame(filename, True, ' ') # specifiy the delimiter
# the line below in the example uses (float)TDatime which I don't know why it renders all the points on the same date
d = rdf.Define("converted_timestamp" ,"TDatime(timestamp).Convert();")
graph = d.Graph('converted_timestamp', 'vmon')
graph.Draw('APL')
xaxis = graph.GetXaxis()
xaxis.SetTimeDisplay(True)
xaxis.SetTimeFormat('%X')
xaxis.SetLabelSize(0.015);
canvas.Modified()
canvas.Update()
input()
Great! Iām glad you could solve this issue. Regarding your doubt with the linked tutorial, in that case the TGraph object is initialized with a constructor that accepts arrays of floats (see here). In your example the Convert() function will return an array of unsigned int, which is just fine since you are creating the graph directly from the RDataFrame .