# Plot a logarithm of a data

**URL:** <https://root-forum.cern.ch/t/plot-a-logarithm-of-a-data/44707>\
**Category:** Newbie\
**Tags:** graphics, root\
**Created:** [May 4, 2021, 9:50am UTC](https://root-forum.cern.ch/t/plot-a-logarithm-of-a-data/44707 "2021-05-04T09:50:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PPierre](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ebca7d/32.png) [@PPierre](https://root-forum.cern.ch/u/PPierre)\
**Post date:** [May 4, 2021, 9:50am UTC](https://root-forum.cern.ch/t/plot-a-logarithm-of-a-data/44707/1 "2021-05-04T09:50:17Z")

</div>

snippet of my data

```auto
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 :

```auto
{
    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 !

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 4, 2021, 10:13am UTC](https://root-forum.cern.ch/t/plot-a-logarithm-of-a-data/44707/2 "2021-05-04T10:13:42Z")

</div>

```auto
  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();

```

---

<div class="post-metadata">

**Author:** ![PPierre](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ebca7d/32.png) [@PPierre](https://root-forum.cern.ch/u/PPierre)\
**Post date:** [May 4, 2021, 10:26am UTC](https://root-forum.cern.ch/t/plot-a-logarithm-of-a-data/44707/3 "2021-05-04T10:26:16Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 4, 2021, 10:40am UTC](https://root-forum.cern.ch/t/plot-a-logarithm-of-a-data/44707/4 "2021-05-04T10:40:06Z")

</div>

[AddPoint](https://root.cern/doc/master/classTGraph.html#a056c11b01569445bfcaf33079cf01f27) is new. Use [SetPoint](https://root.cern/doc/master/classTGraph.html#a0cd3af5cb1b7cdc249002e45a0b32318) if your ROOT version does not have it. Note SetPoint has an extra parameter … look at the doc.
