# Draw TH1D for larger range

**URL:** <https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800>\
**Category:** ROOT\
**Created:** [July 24, 2023, 3:00am UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800 "2023-07-24T03:00:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![NgJunKai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ngjunkai/32/30046_2.png) [@NgJunKai](https://root-forum.cern.ch/u/NgJunKai)\
**Post date:** [July 24, 2023, 3:00am UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800/1 "2023-07-24T03:00:08Z")

</div>

I have a th1d whose range is -10,10  
but i want to plot -15,15  
SetRangeUser(-15,15) draw the th1d for -10,10  
any solution ?

_ROOT Version:_ 6.24.00 (conda\_forge)  
_Platform:_ ubuntu20.04 (wsl)  
_Compiler:_ gcc9

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [July 24, 2023, 7:57am UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800/2 "2023-07-24T07:57:23Z")

</div>

The only solution is to first define an empty histogram from -15 to 15 and draw it first.

Then you plot your original histogram using Draw(“same”)

(probably you then need to adjust the Y zoom at the end)

---

<div class="post-metadata">

**Author:** ![canigia](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/f4b2a3/32.png) [@canigia](https://root-forum.cern.ch/u/canigia)\
**Post date:** [July 26, 2023, 10:03am UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800/3 "2023-07-26T10:03:01Z")

</div>

Hi,

try to use `h->GetXaxis()->SetLimits(-15,15)` instead of `h->SetRangeUser(-15,15)`.

Best,  
Klaus

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [July 26, 2023, 1:45pm UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800/4 "2023-07-26T13:45:42Z")

</div>

But doesn’t SetLimits change the x-data itself, rather than the zoom?

---

<div class="post-metadata">

**Author:** ![canigia](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/f4b2a3/32.png) [@canigia](https://root-forum.cern.ch/u/canigia)\
**Post date:** [July 26, 2023, 1:57pm UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800/5 "2023-07-26T13:57:21Z")

</div>

Oh indeed, you are right!

I just used SetLimits up to now to force the range of the histogram from a TGraph. There you don’t care, since the data is stored in TGraph.

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [July 26, 2023, 5:30pm UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800/6 "2023-07-26T17:30:15Z")

</div>

Yeppp, SetLimits is one of those terrifying ROOT functions that does one thing for TGraph and another for TH1…

---

<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:** [July 27, 2023, 8:18am UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800/7 "2023-07-27T08:18:00Z")

</div>

> [@How to set ranges on axis?](https://root-forum.cern.ch/t/how-to-set-ranges-on-axis/28254):
>
> The viewing range for a histogram axis can be set from bin ifirst to ilast using the method TAxis::SetRange(ifirst, ilast). Example (hpxpy is a 2D histogram): { TFile f("hsimple.root"); hpxpy-\>Draw("colz"); hpxpy-\>GetYaxis()-\>SetRange(22,23); hpxpy-\>GetXaxis()-\>SetRange(18,19); } Sometimes it is more convenient to set this range using “User’s Coordinates” (axis values) rather than bin numbers. To do that one should use TAxis::SetRangeUser(ufirst, ulast). This method computes the cl…

---

<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:** [August 10, 2023, 8:18am UTC](https://root-forum.cern.ch/t/draw-th1d-for-larger-range/55800/8 "2023-08-10T08:18:55Z")

</div>

Closed on August 10, 2023, 8:18am UTC

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