# Rescale x axis of histogram

**URL:** <https://root-forum.cern.ch/t/rescale-x-axis-of-histogram/36403>\
**Category:** ROOT\
**Created:** [October 18, 2019, 9:10am UTC](https://root-forum.cern.ch/t/rescale-x-axis-of-histogram/36403 "2019-10-18T09:10:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Viesturs](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/v/7cd45c/32.png) [@Viesturs](https://root-forum.cern.ch/u/Viesturs)\
**Post date:** [October 18, 2019, 9:10am UTC](https://root-forum.cern.ch/t/rescale-x-axis-of-histogram/36403/1 "2019-10-18T09:10:32Z")

</div>

I have a histogram `h1`. At some point I realise that I want to rescale the x axis by some parameter a.  
For that purpose I can create another histogram `h2` as in the following example:

```auto
void rescale_axis()
{
  TH1F h1 = TH1F("angle", "angle", 10, 0.0, TMath::Pi());
   //...
   //Filling h1
   //...
  TH1F h2 = TH1F("angle/Pi", "angle/Pi", 10, 0.0, 1.0);
  for (unsigned char bind = 0; bind <= h1.GetNbinsX() + 1; bind ++)
    {
      h2.SetBinContent(bind, h1.GetBinContent(bind));
    }
}

```

Is there a way to do the rescale operation on `h1` directly?

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 18, 2019, 9:14am UTC](https://root-forum.cern.ch/t/rescale-x-axis-of-histogram/36403/2 "2019-10-18T09:14:30Z")

</div>

> [@Can we shift histogram for several channels?](https://root-forum.cern.ch/t/can-we-shift-histogram-for-several-channels/12050/2):
>
> I’m not sure if this is fully kosher, but suit yourself : #include "TAxis.h" #include "TH1.h" #include "TArrayD.h" Double\_t ScaleX(Double\_t x) { Double\_t v; v = 10 \* x + 100; // "linear scaling" function example return v; } Double\_t ScaleY(Double\_t y) { Double\_t v; v = 20 \* y + 200; // "linear scaling" function example return v; } Double\_t ScaleZ(Double\_t z) { Double\_t v; v = 30 \* z + 300; // "linear scaling" function example return v; } void ScaleAxis(TAxis \*a, Double\_t (…

---

<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:** [November 1, 2019, 9:14am UTC](https://root-forum.cern.ch/t/rescale-x-axis-of-histogram/36403/3 "2019-11-01T09:14:32Z")

</div>

Closed on November 1, 2019, 9:14am UTC

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