# How to scale Axis Tick Mark Label after RebinX()

**URL:** <https://root-forum.cern.ch/t/how-to-scale-axis-tick-mark-label-after-rebinx/34346>\
**Category:** ROOT\
**Created:** [May 31, 2019, 10:28am UTC](https://root-forum.cern.ch/t/how-to-scale-axis-tick-mark-label-after-rebinx/34346 "2019-05-31T10:28:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajaydeo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@ajaydeo](https://root-forum.cern.ch/u/ajaydeo)\
**Post date:** [May 31, 2019, 10:28am UTC](https://root-forum.cern.ch/t/how-to-scale-axis-tick-mark-label-after-rebinx/34346/1 "2019-05-31T10:28:28Z")

</div>

* * *

_ROOT Version:_ 6.17/01  
_Platform:_ linuxx8664gcc  
_Compiler:_ gcc version 8.3.1 20190223

* * *

Hello,

I have a 1-Dimensional histogram, say h1 with bins going from 0 to 4000. The X-axis tick-mark labels are  
in the interval of 1000 i.e. 0,1000,2000,3000,4000

Now, I rebin X-Axis using

`h1->RebinX(10)`

After this operation the X-axis tick-mark labels are still the same i.e. 0,1000,2000,3000,4000

I want these to change to 0,100,200,300,400 since the calibration of the axis is also changed now. I am not able to get this behaviour.

I tried to search for the answer on the ROOT Forum but the search did led to to relevant post. Also, I am sorry, if this sounds a very simple question.

Regards,

Ajay

---

<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:** [May 31, 2019, 10:37am UTC](https://root-forum.cern.ch/t/how-to-scale-axis-tick-mark-label-after-rebinx/34346/2 "2019-05-31T10:37:25Z")

</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:** ![ajaydeo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@ajaydeo](https://root-forum.cern.ch/u/ajaydeo)\
**Post date:** [May 31, 2019, 1:11pm UTC](https://root-forum.cern.ch/t/how-to-scale-axis-tick-mark-label-after-rebinx/34346/3 "2019-05-31T13:11:07Z")

</div>

Thank you very much! It is working!

But isn’t there a simple way to achieve it? We need this functionality quite frequently with different scaling factors. This means - I have to edit the macro everytime before using it. Isn’t it?

What I was doing was following:

```auto
root [0] .L ScaleAxes.cxx++
root [1] .L ../can2root_utils_cc.so //"can2root_utils.cc stores several macros
root [2] loadF("CtrdShftAna.root");
root [3] td662Vs377_278_bgsub->RebinX(10);
root [4] ScaleXaxis(td662Vs377_278_bgsub, ScaleX);
root [5] td662Vs377_278_bgsub->Draw();
root [6] td662Vs377_278_bgsub->ResetStats();

```

With the above I achieve what I wanted to by changing `v = 10 * x + 100;` to `v = 0.1 * x + 100;` in the original macro in `Double_t ScaleX(Double_t x)` function.

It would have been great to use a scaling factor at **root [4]** instead of using **ScaleX**.

I hope I was using it as it is intended.

With best regards,

Ajay

---

<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:** [May 31, 2019, 2:06pm UTC](https://root-forum.cern.ch/t/how-to-scale-axis-tick-mark-label-after-rebinx/34346/4 "2019-05-31T14:06:05Z")

</div>

If the x-axis is a “fix bin size” one then this should be enough:

```auto
your_histogram->GetXaxis()->SetLimits(new_x_min, new_x_max);
your_histogram->ResetStats();

```

---

<div class="post-metadata">

**Author:** ![ajaydeo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@ajaydeo](https://root-forum.cern.ch/u/ajaydeo)\
**Post date:** [June 1, 2019, 5:13am UTC](https://root-forum.cern.ch/t/how-to-scale-axis-tick-mark-label-after-rebinx/34346/5 "2019-06-01T05:13:57Z")

</div>

Perfect! This is what I was looking for. Thank you once again.

---

<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:** [June 15, 2019, 5:15am UTC](https://root-forum.cern.ch/t/how-to-scale-axis-tick-mark-label-after-rebinx/34346/6 "2019-06-15T05:15:38Z")

</div>

Closed on June 15, 2019, 5:15am UTC

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