# Adjust xAxis in Canvas

**URL:** <https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420>\
**Category:** ROOT\
**Tags:** root\
**Created:** [May 14, 2020, 11:26pm UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420 "2020-05-14T23:26:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yassine](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/yassine/32/34003_2.png) [@yassine](https://root-forum.cern.ch/u/yassine)\
**Post date:** [May 14, 2020, 11:26pm UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420/1 "2020-05-14T23:26:44Z")

</div>

Hi,

I would like to adjust xAxis of a variable within my tree.

when I draw it by simply doing

Tree-\>Draw("") I got

 ![cluster_secondLambda_10](https://root-forum.cern.ch/uploads/default/original/3X/b/2/b2e04b5858d9599f87cb86f0f2ace85041e1d387.png)

Now adjusting the xAxis by doing  
gROOT-\>cd();  
TH1D \*h = new TH1D(“h”,“cluster\_secondLambda”,100,0,8000);  
t-\>Draw(“cluster\_centerLambda\>\>h”);

I got this new one

 ![cluster_secondLambda_10_10K](https://root-forum.cern.ch/uploads/default/original/3X/a/f/af0c47633cc90234d88662843075772d278ac440.png)

The question is I wasn’t expected that vertical axis will be changed ? I’m not sure what I did is correct or not

Thanks

---

<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:** [May 15, 2020, 6:24am UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420/2 "2020-05-15T06:24:04Z")

</div>

> [@yassine](#):
>
> The question is I wasn’t expected that vertical axis will be changed ? I’m not sure what I did is correct or not

The number of bins … both histograms have 100 … but the ranges are totally different on X. reduce the number of bins for the 2nd one and the maximum will be higher. Or use the 1st one and change the X axis range of the htemp histogram created by the TTrre::Draw command

---

<div class="post-metadata">

**Author:** ![yassine](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/yassine/32/34003_2.png) [@yassine](https://root-forum.cern.ch/u/yassine)\
**Post date:** [May 15, 2020, 10:25am UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420/3 "2020-05-15T10:25:04Z")

</div>

changing the xAxis is what really am intending to do. Is what I did here correct ? BTW is there another to change xAxis of the histog crated by TTree?

thanks a lot

---

<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:** [May 15, 2020, 10:48am UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420/4 "2020-05-15T10:48:43Z")

</div>

> [@yassine](#):
>
> Is what I did here correct ?

Not really because you kept the same number of bins.

> [@yassine](#):
>
> is there another to change xAxis of the histog crated by TTree?

Yes:

```auto
Tree->Draw("x")
auto htemp = (TH1F*)gPad->GetPrimitive("htemp");
htemp->GetXaxis()->SetRangeUser(0.,8000.)

```

---

<div class="post-metadata">

**Author:** ![RENATO\_QUAGLIANI](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/renato_quagliani/32/19496_2.png) [@RENATO\_QUAGLIANI](https://root-forum.cern.ch/u/RENATO_QUAGLIANI)\
**Post date:** [May 15, 2020, 1:39pm UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420/5 "2020-05-15T13:39:37Z")

</div>

Isnt the  
Tree-\>Draw(“var\>\>htemp(100,0,3000)”) enough to customize the default root drawing in 1 line of code?

---

<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:** [May 18, 2020, 8:51am UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420/6 "2020-05-18T08:51:19Z")

</div>

Yes that’s equivalent of what @yassine did. But the number of bin is still an issue if you want to keep the same maximum as with the full range.

---

<div class="post-metadata">

**Author:** ![yassine](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/yassine/32/34003_2.png) [@yassine](https://root-forum.cern.ch/u/yassine)\
**Post date:** [May 18, 2020, 10:46am UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420/7 "2020-05-18T10:46:06Z")

</div>

Thanks that’s was helpful. keeping the same binning while reducing the x range results really on a quiet no informative distribution.

---

<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 1, 2020, 10:46am UTC](https://root-forum.cern.ch/t/adjust-xaxis-in-canvas/39420/8 "2020-06-01T10:46:13Z")

</div>

Closed on June 1, 2020, 10:46am UTC

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