Extra point at (0,0) using TGraph

Hi,
When I plot a graph using data from a text file, by default a point is set at (0,0).
The script that I used is:

FILE *fpm = fopen(“data.txt”, “r”);

int i=0;
double a,b;

TGraph *ab = new TGraph();

while (fscanf(fpm, “%lf\t%lf”, &a, &b)!=EOF) {
i++;
ab->SetPoint(i,a,b);
}
ab->SetMarkerStyle(20);
ab->SetMarkerSize(1.4);
ab->SetTitle(“Viola”);
ab->Draw(“P”);

_ROOT Version:6.14/04
_Platform:Ubuntu 18.04 LTS


Hi,

Just change order of operations:

ab->SetPoint(i,a,b);
i++;

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