TGraphErrors from txt file

Hello,

I am using this code to draw a graph with errors from a txt file:

    TGraphErrors *g = new TGraphErrors("myFile.txt");
    g->SetTitle(
       "Title;"
       "x axis title;"
       "y axis title");
    
    g->SetMarkerStyle(21);
    g->SetMarkerColor(kRed);
    g->Draw("AP"); //"P" is a must to activate the above "SetMarkerStyle"
    
    if (gPad) gPad->SetLogy(0);
    g->SetMinimum(0.001);
    gPad->SetLogy(1);

However, I get this (no error bars shown):

Capture1

Thanks!

What does the “myFile.txt” contain?

Just normal X and Y data points:

X Y
… …
… …
… …

and so on.

So, you do not provide errors at all.

I added like three set of values for Y so root can calculate the std deviation. Isn’t that how it works?

What are you talking about?

See the constructor reading input from a file: TGraphErrors::TGraphErrors

Ok I did the measurements like 3 times and ended up with:

X1 X2 X3 Y1 Y2 Y3

So these are columns of data for which I could manually calculate errors, but I wanted to do it automatically in root.

You need to write a loop over your data and calculate everything yourself.

Yes I see it now. Thanks.

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