Home | News | Documentation | Download

Plot a logarithm of a data

snippet of my data

0.0 994
0.1 994
0.2 985
0.3 982
0.4 965
0.5 969
0.6 962
0.7 957
0.8 952

My code :

{
    TGraph* gr = new TGraph("myFileENERGIE.txt");
    gr->Draw("AC*");
}

My question :
How could I plot the same graph but passing the natural logarithm to the datas in the first column ?

Well I don’t know, something simple like TGraph* gr = new TGraph(“myFileENERGIE.txt”, ln(%lg) %lg); ?

I guess, as recommended in other topics in the forum, that I could read my text file and store my data in some vectors but I hope there a faster way.

Thanks !

  ifstream data("data.txt"); 
   for(Int_t i = 0 ; i < 9 ; i++){
          data >> x >> y;
          .... compute the log of x an/or y (xl,yl)
        gr->AddPoint(xl,yl);
   }
    data.close();

Okok thanks @couet for your answer. But AddPoint() doesn’t belong to the class TGraph right ?
Well it doesn’t work, I even tried SetPoint() method…

AddPoint is new. Use SetPoint if your ROOT version does not have it. Note SetPoint has an extra parameter … look at the doc.

1 Like