# How to use SetRangeUser

**URL:** <https://root-forum.cern.ch/t/how-to-use-setrangeuser/26035>\
**Category:** ROOT\
**Created:** [August 27, 2017, 4:46pm UTC](https://root-forum.cern.ch/t/how-to-use-setrangeuser/26035 "2017-08-27T16:46:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nab](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nab](https://root-forum.cern.ch/u/nab)\
**Post date:** [August 27, 2017, 4:46pm UTC](https://root-forum.cern.ch/t/how-to-use-setrangeuser/26035/1 "2017-08-27T16:46:14Z")

</div>

Dear developers,

I want to change the x-axis range of my histograms and then stack on each other in range 60-120. I am using the SetRangeUser command but it is not working. Kindly see my script to resolve it.

Thanks.  
Nab

[stack\_z\_try.cc](https://root-forum.cern.ch/uploads/default/original/2X/a/a5076cb4c37bde2ed684ab469312de1622dd74fb.cc) (2.6 KB)

---

<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:** [August 27, 2017, 5:50pm UTC](https://root-forum.cern.ch/t/how-to-use-setrangeuser/26035/2 "2017-08-27T17:50:58Z")

</div>

> [@SetAxisRange(0.0,1.0,"Y"); is ineffective](https://root-forum.cern.ch/t/setaxisrange-0-0-1-0-y-is-ineffective/14040/4):
>
> From my experience … for a TH1 I am usually using something like this: histo-\>Draw(); histo-\>SetAxisRange(xmin, xmax, “X”); histo-\>SetAxisRange(ymin, ymax, “Y”); histo-\>Draw(); // make sure it’s redrawn If I am dealing with a THStack of several TH1 histograms, I am usually using something like this: stack-\>Draw(“H”); stack-\>GetXaxis()-\>SetLimits(xmin, xmax); stack-\>SetMinimum(ymin); stack-\>SetMaximum(ymax); stack-\>Draw(“H”); // make sure it’s redrawn

> [@Palette on a TProfile2d](https://root-forum.cern.ch/t/palette-on-a-tprofile2d/14704/2):
>
> Try: h4bprof-\>SetAxisRange(8, 20, “Z”); and/or: h4bprof-\>GetZaxis()-\>SetRangeUser(8, 20); Actually, I believe this should work as well: h4bprof-\>SetMinimum(8); h4bprof-\>SetMaximum(20); See also: [url][SetAxisRange(0.0,1.0,“Y”); is ineffective](https://root-forum.cern.ch/t/setaxisrange-0-0-1-0-y-is-ineffective/14040/1) [url][Drawing a TGraphAsymmErrors](https://root-forum.cern.ch/t/drawing-a-tgraphasymmerrors/14205/1) BTW. You have a typo in your “tree.c” file in line 356 … “SetMinimun” does NOT exist at all (note that the last character in this name is a “n” instead of a “m”) … I think that’s where your problem originates …

> [@SetRangeUser and SetTitle working with THStacks and TH1F obj](https://root-forum.cern.ch/t/setrangeuser-and-settitle-working-with-thstacks-and-th1f-obj/12114/2):
>
> I once had similar problems. Here’s what I’ve found to be working (don’t ask me why, no idea). THStack \*hs = (THStack \*)0; hs = new THStack(\*hs\_ORIG); // do not modify the "hs\_ORIG" THStack, create a copy hs-\>Draw("H NOSTACK"); hs-\>GetHistogram()-\>SetXTitle("My X Title"); hs-\>GetHistogram()-\>SetYTitle("My Y Title"); hs-\>GetXaxis()-\>SetTitleOffset(1.0); hs-\>GetYaxis()-\>SetTitleOffset(1.5); hs-\>GetYaxis()-\>CenterTitle(kTRUE); hs-\>GetXaxis()-\>SetLimits(0, 10.001); // "xmin", "xmax" hs-\>SetMinimum(…

> [@Plotting a portion of a histogram?](https://root-forum.cern.ch/t/plotting-a-portion-of-a-histogram/22053/2):
>
> { gStyle-\>SetOptFit(); TH1::SetDefaultSumw2(kTRUE); // ensure proper error propagation TH1D \*counts = new TH1D("counts", "full histogram", 100, -5, 5); // counts-\>Sumw2(kTRUE); // not needed if "TH1::SetDefaultSumw2" counts-\>FillRandom("gaus", 11000); TH1D \*bgcounts = new TH1D("bgcounts", "background", 100, -5, 5); // bgcounts-\>Sumw2(kTRUE); // not needed if "TH1::SetDefaultSumw2" bgcounts-\>FillRandom("gaus", 1000); TH1D \*noBgCounts = new TH1D(\*counts); // make a copy of "count…

---

<div class="post-metadata">

**Author:** ![nab](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nab](https://root-forum.cern.ch/u/nab)\
**Post date:** [August 28, 2017, 5:40am UTC](https://root-forum.cern.ch/t/how-to-use-setrangeuser/26035/3 "2017-08-28T05:40:07Z")

</div>

Thank you. But I tried all the commands still my histogram is not changing the range.  
But when I use hs-\>SetMinimum(20); it changes the yaxis but i want to change xaxis range.

---

<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:** [September 4, 2017, 1:04pm UTC](https://root-forum.cern.ch/t/how-to-use-setrangeuser/26035/4 "2017-09-04T13:04:50Z")

</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:** [September 18, 2017, 1:04pm UTC](https://root-forum.cern.ch/t/how-to-use-setrangeuser/26035/5 "2017-09-18T13:04:59Z")

</div>

Closed on September 18, 2017, 1:04pm UTC

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