# Changing the scale for graph?

**URL:** <https://root-forum.cern.ch/t/changing-the-scale-for-graph/17339>\
**Category:** ROOT\
**Created:** [March 11, 2014, 3:59pm UTC](https://root-forum.cern.ch/t/changing-the-scale-for-graph/17339 "2014-03-11T15:59:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jfcaron](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jfcaron](https://root-forum.cern.ch/u/jfcaron)\
**Post date:** [March 11, 2014, 7:12pm UTC](https://root-forum.cern.ch/t/changing-the-scale-for-graph/17339/2 "2014-03-11T19:12:09Z")

</div>

I have a PyROOT function which accomplishes the X-axis rescaling, you could re-write it in C++ (basically add curly braces and types).

```auto
def rescaleaxis(g,scale=50e-12/1e-9):
    """This function rescales the x-axis on a TGraph."""
    N = g.GetN()
    x = g.GetX()
    for i in range(N):
        x[i] *= scale
    g.GetHistogram().Delete()
    g.SetHistogram(0)
    return
```

Here are some references on how I obtained that code:  
[url][Feature Request: Transform TAxes](https://root-forum.cern.ch/t/feature-request-transform-taxes/16327/1)  
[root.cern.ch/phpBB3/viewtopic.php?f=3&t=15953](http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=15953)

For the Y-axis, I think you can do the same thing but with GetY(). I tried doing another trick by converting to a TH1, TH1::Scale, then converting back to TGraph, but it didn’t work for some reason. I’ll admit I didn’t try very hard to make this trick work.

Jean-François

---

_[View the full topic](https://root-forum.cern.ch/t/changing-the-scale-for-graph/17339)._
