# Change units of y-axis in a TH2D histogram

**URL:** <https://root-forum.cern.ch/t/change-units-of-y-axis-in-a-th2d-histogram/52076>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [October 25, 2022, 6:58am UTC](https://root-forum.cern.ch/t/change-units-of-y-axis-in-a-th2d-histogram/52076 "2022-10-25T06:58:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [October 25, 2022, 6:58am UTC](https://root-forum.cern.ch/t/change-units-of-y-axis-in-a-th2d-histogram/52076/1 "2022-10-25T06:58:36Z")

</div>

I want to change the units of the y-axis of a TH2D histogram in the way of `y = y*c` where `c` is some constant. What is the easiest and cleanest way to do this?

---

<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 25, 2022, 7:36am UTC](https://root-forum.cern.ch/t/change-units-of-y-axis-in-a-th2d-histogram/52076/3 "2022-10-25T07:36:41Z")

</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:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [October 27, 2022, 5:35am UTC](https://root-forum.cern.ch/t/change-units-of-y-axis-in-a-th2d-histogram/52076/4 "2022-10-27T05:35:18Z")

</div>

Thank you! It worked great. Is there a reason why this is not a built-in function? It is very useful

---

<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 27, 2022, 6:55am UTC](https://root-forum.cern.ch/t/change-units-of-y-axis-in-a-th2d-histogram/52076/5 "2022-10-27T06:55:59Z")

</div>

Nobody cares.

> [@TAxis FixedToVariable and VariableToFixed proposal](https://root-forum.cern.ch/t/taxis-fixedtovariable-and-variabletofixed-proposal/30048):
>
> I would like to propose that two methods are added to the TAxis class: FixedToVariable and VariableToFixed. So, an axis which was created as a “fixed bin sizes” one could be converted into a “variable bin sizes” one and the opposite. Note: in case of the “VariableToFixed” method, we would not preserve bin widths, only the “low-edge”, the “upper-edge” and the number of bins would be used / preserved. I guess I would like to have: FixedToVariable(Double\_t \*xbins = 0) FixedToVariable(Double\_t x…

---

<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:** [October 27, 2022, 7:24am UTC](https://root-forum.cern.ch/t/change-units-of-y-axis-in-a-th2d-histogram/52076/6 "2022-10-27T07:24:39Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> Nobody cares.

I think @moneta can help.
