# TGraph SetLimits

**URL:** <https://root-forum.cern.ch/t/tgraph-setlimits/33144>\
**Category:** ROOT\
**Tags:** python, root\
**Created:** [March 13, 2019, 4:34pm UTC](https://root-forum.cern.ch/t/tgraph-setlimits/33144 "2019-03-13T16:34:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iMi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@iMi](https://root-forum.cern.ch/u/iMi)\
**Post date:** [March 13, 2019, 4:34pm UTC](https://root-forum.cern.ch/t/tgraph-setlimits/33144/1 "2019-03-13T16:34:23Z")

</div>

* * *

\_ROOT Version: 6.14  
\_PYTHON Version : 3.6.7  
\_Platform: Debian 9  
\_Compiler: GCC 7.3.0

* * *

Hi, I frequently use the method below to reassign the axes of a square 2D histogram with physical units (in this case pixels are converted to mm)

```auto
def PixToMM(h1): 
    sizeAxis = h1.GetXaxis().GetNbins()
    dimensions = ((sizeAxis-2)/43.5)*0.474*m
    h1.GetXaxis().SetLimits(0., dimensions)
    h1.GetYaxis().SetLimits(0., dimensions)
    h1.GetXaxis().SetTitle("mm")
    h1.GetYaxis().SetTitle("mm")

```

When I try a similar method for a TGraph object, it does not work as I wished it would. SetLimits() for the TGraph Object behaves like SetRangeUser() for a histogram.

Here, some pseudo code to illustrate what I mean :

```auto
bin_number = tgraph.GetXaxis().GetNbins() 
dimensions = ((bin_number-2)/43.5)*0.474*m 
tgraph.GetXaxis().SetLimits(0., dimensions) ---> This line behaves as SetRangeUser() normally does.

```

Do you have any suggestions how to convert the x-axis from pixels to mm if SetLimits does not work here?

---

<div class="post-metadata">

**Author:** ![RongkunWang](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rongkunwang/32/36036_2.png) [@RongkunWang](https://root-forum.cern.ch/u/RongkunWang)\
**Post date:** [March 13, 2019, 6:47pm UTC](https://root-forum.cern.ch/t/tgraph-setlimits/33144/2 "2019-03-13T18:47:51Z")

</div>

Hi,

For TGraph, GetXaxis() returns sth defined [here](https://root.cern.ch/doc/master/TGraph_8cxx_source.html#l01470)

It returns a histogram

I’m not a frequent user of SetLimits, but when I draw with TGraph, I always first draw a TH1 myself, then I manipulate the TH1 for everything, just because I’m more familiar with THistogram’s behavior.

---

<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:** [March 14, 2019, 8:23am UTC](https://root-forum.cern.ch/t/tgraph-setlimits/33144/3 "2019-03-14T08:23:08Z")

</div>

There is an HowTo about his:

> [@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:** [March 28, 2019, 8:23am UTC](https://root-forum.cern.ch/t/tgraph-setlimits/33144/4 "2019-03-28T08:23:11Z")

</div>

Closed on March 28, 2019, 8:23am UTC

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