# Force the exponent on the y-axis of a TGraph

**URL:** <https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167>\
**Category:** ROOT\
**Created:** [March 20, 2025, 7:37am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167 "2025-03-20T07:37:37Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [March 20, 2025, 7:37am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/1 "2025-03-20T07:37:38Z")

</div>

Hello, is there a way to force the exponent of the scientific notation in the TGraph?

I mean, I get a scale \*10^-6. I would like to get in 10^-5

I even tried the DrawFrame as @couet used here [TGraph set maximum number of digits not working - #6 by couet](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/6), in addition to the SetMaxDigits, but without results…

[lcdata.txt](https://root-forum.cern.ch/uploads/short-url/wsCi4hQQ6TDY9RkU9RYaRZkVabF.txt) (72 Bytes)

 ![LCPeakflare](https://root-forum.cern.ch/uploads/default/original/3X/7/e/7e27c0087c9b7703178c9e9c96abab18c2ffdeed.png)  
[lcplot.cpp](https://root-forum.cern.ch/uploads/short-url/6zxJZvgcCpYPmaIkeFgykRgQMtb.cpp) (2.3 KB)

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [March 20, 2025, 7:49am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/2 "2025-03-20T07:49:25Z")

</div>

A workaround would be:

```auto
graph->Scale(1./1e-5, "y");
graph->GetYaxis()->SetTitle("Flux Mev ... / 1e-5)

```

---

<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:** [March 20, 2025, 8:17am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/3 "2025-03-20T08:17:56Z")

</div>

Yes the power of 10 are multiple of 3. Note that in you example DrawFrame is useless as you draw the graph with option "A’ which will redraw the axis.

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [March 20, 2025, 9:43am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/4 "2025-03-20T09:43:43Z")

</div>

thank you the both.  
i tried the scale, but the points disappear and i still get 10^-6

[lcdata.txt](https://root-forum.cern.ch/uploads/short-url/wsCi4hQQ6TDY9RkU9RYaRZkVabF.txt) (72 Bytes)

 ![LCPeakflare](https://root-forum.cern.ch/uploads/default/original/3X/e/e/ee481e9c0f49df6f30a8952e8b3c66a70fecbd22.png)  
[lcplot.cpp](https://root-forum.cern.ch/uploads/short-url/x9z667hydrexPg2NspnKNxTwOex.cpp) (2.3 KB)

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [March 20, 2025, 10:00am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/5 "2025-03-20T10:00:32Z")

</div>

Try calling Scale earlier in the script, just after new TGraphErrors

@couet do you know why it depends on what position it is called frmo?

---

<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:** [March 20, 2025, 10:08am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/6 "2025-03-20T10:08:23Z")

</div>

The following works for me:

```auto
void lcplot() {
   TGraphErrors *graph1 = new TGraphErrors("LCdata.txt","%lg %lg %lg %lg");
   graph1->Scale(1./1e-5, "y");
   graph1->Draw("AP");
}

```

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [March 20, 2025, 10:26am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/7 "2025-03-20T10:26:18Z")

</div>

Ok, thanks, so this works:

```auto
void lcplot() {
   TGraphErrors *graph1 = new TGraphErrors("LCdata.txt","%lg %lg %lg %lg");
   graph1->Scale(1./1e-5, "y");
   graph1->GetXaxis()->SetLimits(60479, 60492);
   graph1->Draw("AP");
}

```

but this fails:

```auto
void lcplot() {
   TGraphErrors *graph1 = new TGraphErrors("LCdata.txt","%lg %lg %lg %lg");
   graph1->GetXaxis()->SetLimits(60479, 60492);
   graph1->Scale(1./1e-5, "y");
   graph1->Draw("AP");
}

```

Not sure if Scale should be modified to update the y-limits if x-limits were set.

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [March 20, 2025, 10:45am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/8 "2025-03-20T10:45:29Z")

</div>

Hello, thank you.  
Moving the

```auto
graph1->Scale(1./1e-5, "y");

```

just after  
`GraphErrors *graph1 = new TGraphErrors("LCdata.txt","%lg %lg %lg %lg");`

set the 10^-5 scale…  
but the 10^-5 factor  
[lcdata.txt](https://root-forum.cern.ch/uploads/short-url/wsCi4hQQ6TDY9RkU9RYaRZkVabF.txt) (72 Bytes)

 ![LCPeakflare](https://root-forum.cern.ch/uploads/default/original/3X/1/4/14eedcf52c7b51bf22aff9445f961f7b76e34723.png)  
[lcplot.cpp](https://root-forum.cern.ch/uploads/short-url/cvWUciNj9nfZ7tzj8NhneeQghTt.cpp) (2.3 KB)  
disappears…

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [March 20, 2025, 11:02am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/9 "2025-03-20T11:02:21Z")

</div>

> [@faca87](#):
>
> disappears…

Yes, it disappears, that’s the idea / trick. Set it instead in the Y-axis title.

graph1-\>GetYaxis()-\>Settitle (“flux / 1e-5”);

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [March 20, 2025, 11:07am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/10 "2025-03-20T11:07:17Z")

</div>

Unfortunately, it’s quite orrible to write it in the y-title…

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [March 20, 2025, 11:18am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/11 "2025-03-20T11:18:21Z")

</div>

You can write it instead as a TText or TLatex object at the desired position.

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [March 20, 2025, 11:25am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/12 "2025-03-20T11:25:27Z")

</div>

Yes good solution!

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 3, 2025, 11:26am UTC](https://root-forum.cern.ch/t/force-the-exponent-on-the-y-axis-of-a-tgraph/63167/13 "2025-04-03T11:26:06Z")

</div>

Closed on April 3, 2025, 11:26am UTC

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