Unable to make plot

What I want to do is read the data from a csv file, and then plot it. The csv has several (I believe 7, but not sure) columns. However, for simplicity I first tried to plot just the first two columns. The code that I ran is the following:

// Reads the points from a file and produces a simple graph.  
int macro2(){  
auto c=new TCanvas();c->SetGrid();  `

`TGraph graph("/home/tarabostes-delectus/build/datapicolog/PicoLog data/basic.csv","%lg %*lg %lg ", ",");  
graph.SetMarkerStyle(kCircle);  `


`graph.Print();  
return 0;  
}

However when I try in the console:
.L RPCSV.C macro2()

I get nothing

can you post basic.csv ? (or a reduced version of it).

This link does not work.

Did you try the new one? I edited the post.

Yes … I click on the link and get an error

I will try and find another online file sharing service. One moment please

you can also just copy/paste here the fist 10 lines of the file … that will be enough to debug.

Time,B_x ,B_y,B_z,Thermometer LMTZ70,B0_x,B0_y,B0_z  
$\Delta$Seconds, (mV), (mV), and so on   
$\Delta$
0,-1,114,0,599,8,128,-981,486,-459,880,-901,682,-913,506    
1,-1,112,0,599,8,128,-981,433,-459,880,-901,682,-913,506
2,-1,107,0,611,8,136,-981,410,-459,882,-901,682,-913,506
3,-1,107,0,612,8,142,-981,378,-459,887,-901,734,-913,519
4,-1,111,0,608,8,142,-981,106,-459,887,-901,744,-913,533
5,-1,113,0,601,8,141,-981,106,-459,867,-901,730,-913,533
6,-1,112,0,601,8,141,-981,234,-459,855,-901,692,-913,509
7,-1,108,0,600,8,148,-981,350,-459,856,-901,692,-913,506
8,-1,108,0,599,8,158,-981,350,-459,869,-901,656,-913,486
9,-1,108,0,601,8,158,-981,925,-459,869,-901,639,-913,443
10,-1,109,0,608,8,137,-981,957,-459,886,-901,642,-913,443
11,-1,109,0,608,8,132,-981,941,-459,907,-901,662,-913,484
12,-1,120,0,600,8,131,-981,914,-459,907,-901,662,-913,499
13,-1,121,0,594,8,130,-981,914,-459,874,-901,661,-913,493
14,-1,120,0,594,8,130,-982,065,-459,867,-901,660,-913,443
15,-1,119,0,611,8,148,-982,115,-459,873,-901,660,-913,443
16,-1,119,0,611,8,158,-982,068,-459,888,-901,650,-913,442
17,-1,125,0,609,8,156,-981,816,-459,888,-901,649,-913,442
18,-1,127,0,607,8,114,-981,816,-459,891,-901,658,-913,442
19,-1,126,0,607,8,114,-981,954,-459,893,-901,677,-913,486
20,-1,121,0,596,8,122,-982,055,-459,894,-901,677,-913,488
21,-1,121,0,593,8,134,-982,055,-459,913,-901,681,-913,487
22,-1,119,0,595,8,134,-982,001,-459,913,-901,682,-913,483
23,-1,117,0,604,8,118,-982,001,-459,896,-901,678,-913,483
24,-1,117,0,604,8,115,-982,062,-459,877,-901,645,-913,490
25,-1,128,0,605,8,119,-982,167,-459,877,-901,645,-913,493
26,-1,129,0,605,8,132,-982,167,-459,863,-901,687,-913,510
27,-1,127,0,605,8,132,-981,896,-459,861,-901,725,-913,599
28,-1,123,0,606,8,133,-981,824,-459,836,-901,725,-913,599
29,-1,123,0,606,8,133,-981,874,-459,767,-901,634,-913,550
30,-1,118,0,606,8,134,-982,138,-459,767,-901,624,-913,505
31,-1,116,0,606,8,145,-982,138,-459,825,-901,652,-913,505
32,-1,117,0,606,8,145,-981,974,-459,853,-901,712,-913,573

Maybe it is related to the fact that the first few lines are not integers?

No, your macro was wrong. Try:

void macro2(){
   auto c=new TCanvas();c->SetGrid();

   auto graph = new TGraph("basic.csv","%lg %*lg %lg ", ",");
   graph->SetMarkerStyle(kCircle);

   graph->Print();
   graph->Draw("APL");
}
1 Like

Thank you, now it works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.