Hi experts,
I have data stored in a .csv file(name"ytt_yt.csv") as following picture. How can I read data from the csv file and plot a graph using the thrid and fourth columns? Take the third columns as x axis and the fourth column as y axis.
thank you
best regards,
Winston
There is several posts on this topic in this forum. Have you tried to search the forum with “csv” ?
{
TTree *t = new TTree("t", "tree from ytt_yt.csv");
t->ReadFile("ytt_yt.csv", "yt0_X/D:yt0_Y:yt3_X:yt3_Y:yt1_X:yt1_Y:yt2_X:yt2_Y");
t->Draw("yt3_Y : yt3_X");
}
Hi Wile,
thank you. I tried your method, but it encountered an error:
Warning in TTree::ReadStream: Couldn’t read formatted data in “yt0_X” for branch yt0_Y on line 1; ignoring line
Warning in TTree::ReadStream: Read too few columns (2 < 8) in line 1; ignoring line
Warning in TTree::ReadStream: Ignoring trailing “,-0.0249839568,” while reading line 2
Warning in TTree::ReadStream: Ignoring trailing “,-0.0255424498,” while reading line 3
…
Attach your “ytt_yt.csv” file for inspection.
To upload the file I tranform the postfix into .txt, please first change it back to .csv.
Thanks for your attention.
ytt_yt.txt (17.3 KB)
ROOT expects all lines with exactly 8 values separated by single “,
” characters.
You need to remove “empty” / “nonexistent” values (i.e. there must be no “,,
”).
Also, remove the very first line completely.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.