# Setting a histogram x axis rage for a splitted histogram?

**URL:** <https://root-forum.cern.ch/t/setting-a-histogram-x-axis-rage-for-a-splitted-histogram/57320>\
**Category:** Newbie\
**Created:** [November 29, 2023, 8:42am UTC](https://root-forum.cern.ch/t/setting-a-histogram-x-axis-rage-for-a-splitted-histogram/57320 "2023-11-29T08:42:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [November 29, 2023, 8:42am UTC](https://root-forum.cern.ch/t/setting-a-histogram-x-axis-rage-for-a-splitted-histogram/57320/1 "2023-11-29T08:42:25Z")

</div>

Hi folks,

I have been trying to draw two histograms stacked on top of each other by splitting the parent histogram into two sets of axis ranges. I have divided the canvas. However, I am not able to set the x-axis ranges for both separately ? When I use

 ![2hist on one canvas](https://root-forum.cern.ch/uploads/default/original/3X/1/e/1ea8518669a05344df559eca9f6d664683075bb3.png)

```auto
c1->cd(1)
h1->GetXaxis()->SetRangeUser(0, 0.5)
c1->cd(2)
h1->GetXaxis()->SetRangeUser(0.5, 1)

```

It changes the X-axis for both the histogram ranges. I am trying to set the range 0 to 0.5 for above and 0.5 to 1 for below.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 29, 2023, 8:58am UTC](https://root-forum.cern.ch/t/setting-a-histogram-x-axis-rage-for-a-splitted-histogram/57320/2 "2023-11-29T08:58:39Z")

</div>

Well, you call `SetRangeUser()` twice on the same histogram, so this is not going to work. But I’m sure @couet will tell you how to do it properly

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [November 29, 2023, 9:08am UTC](https://root-forum.cern.ch/t/setting-a-histogram-x-axis-rage-for-a-splitted-histogram/57320/3 "2023-11-29T09:08:24Z")

</div>

Oh I see, thanks for highlighting the issue.

---

<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:** [November 29, 2023, 10:04am UTC](https://root-forum.cern.ch/t/setting-a-histogram-x-axis-rage-for-a-splitted-histogram/57320/4 "2023-11-29T10:04:21Z")

</div>

```auto
c1->cd(1);
h1->Draw();
h1->GetXaxis()->SetRangeUser(0, 0.5);
c1->cd(2);
h1->DrawCopy()->GetXaxis()->SetRangeUser(0.5, 1)

```

should work I guess…

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [November 29, 2023, 10:09am UTC](https://root-forum.cern.ch/t/setting-a-histogram-x-axis-rage-for-a-splitted-histogram/57320/5 "2023-11-29T10:09:50Z")

</div>

Yeah, it works like a charm ! Thanks a lot.
