# Retrieve TPad ranges after DrawFrame

**URL:** <https://root-forum.cern.ch/t/retrieve-tpad-ranges-after-drawframe/45085>\
**Category:** Newbie\
**Created:** [May 26, 2021, 10:29am UTC](https://root-forum.cern.ch/t/retrieve-tpad-ranges-after-drawframe/45085 "2021-05-26T10:29:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gasar8](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gasar8/32/21054_2.png) [@gasar8](https://root-forum.cern.ch/u/gasar8)\
**Post date:** [May 26, 2021, 10:29am UTC](https://root-forum.cern.ch/t/retrieve-tpad-ranges-after-drawframe/45085/1 "2021-05-26T10:29:41Z")

</div>

I am adding a vertical line to a ratio plot TPad and want it to go from bottom all the way up to the top of the pad. I successfully achieved this either by getting the y range via `pad->GetUymin() / max()` or by `pad->GetRangeAxis(xmin, ymin, xmax, ymax)`. However, in our framework we can switch from ratio plot to signal significance plot in which case, I have some difficulties getting the range correctly. The only difference I see in the code, is that in the significance case, a TH1 is plotted to the pad via `TH1 *frame = pad->DrawFrame(...)` and then, its range is set as `frame->GetYaxis()->SetRangeUser(0, maxValue)`. In this case, with my settings, the vertical line is always drawn only in (0, 1) range for both of my approaches. Is this the desired behaviour or should `GetUymin() / max()` and `GetRangeAxis()` return the true y limits?  
How can I retrieve the right y range from the TH1 embedded to my pad then?

_ROOT Version:_ v6.24.00  
_Platform:_ centos7  
_Compiler:_ gcc10

* * *

---

<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 26, 2021, 10:45am UTC](https://root-forum.cern.ch/t/retrieve-tpad-ranges-after-drawframe/45085/2 "2021-05-26T10:45:25Z")

</div>

It seems ok for me but may be that’s not the problem you encounter:

```auto
void lineonpad() {
   auto C = new TCanvas();
   gPad->DrawFrame(4.,0., 10.,5.);
   auto l = new TLine();
   l->DrawLine(7.,gPad->GetUymin(),7., gPad->GetUymax());
}

```

 ![Screenshot 2021-05-26 at 12.45.07](https://root-forum.cern.ch/uploads/default/original/3X/e/6/e6b523b1daff08028d91f204aba76b6ef97dbab9.jpeg)

---

<div class="post-metadata">

**Author:** ![gasar8](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gasar8/32/21054_2.png) [@gasar8](https://root-forum.cern.ch/u/gasar8)\
**Post date:** [May 26, 2021, 10:58am UTC](https://root-forum.cern.ch/t/retrieve-tpad-ranges-after-drawframe/45085/3 "2021-05-26T10:58:53Z")

</div>

Hi, thank you for your prompt reply. This also works for me, but in the code, the `DrawFrame()` is assigned to a TH1 and new range is then set to this TH1. If I add this to your code, it breaks the ranges:

```auto
void lineonpad() {
   auto C = new TCanvas();
   TH1 *frame = gPad->DrawFrame(4.,0., 10.,1.);
   frame->GetYaxis()->SetRangeUser(0,10);
   auto l = new TLine();
   l->DrawLine(7.,gPad->GetUymin(),7., gPad->GetUymax());
}

```

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/a/5/a55265f6769c666e2449105bfdbe6ccc86c967d5.png)

Is this the wrong approach?

---

<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 26, 2021, 12:04pm UTC](https://root-forum.cern.ch/t/retrieve-tpad-ranges-after-drawframe/45085/4 "2021-05-26T12:04:13Z")

</div>

Do:

```auto
void lineonpad() {
   auto C = new TCanvas();
   TH1 *frame = gPad->DrawFrame(4.,0., 10.,1.);
   frame->GetYaxis()->SetRangeUser(0,10);
   gPad->Modified(); gPad->Update();
   auto l = new TLine();
   l->DrawLine(7.,gPad->GetUymin(),7., gPad->GetUymax());
}

```

And I will be fine.

---

<div class="post-metadata">

**Author:** ![gasar8](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gasar8/32/21054_2.png) [@gasar8](https://root-forum.cern.ch/u/gasar8)\
**Post date:** [May 26, 2021, 12:45pm UTC](https://root-forum.cern.ch/t/retrieve-tpad-ranges-after-drawframe/45085/5 "2021-05-26T12:45:30Z")

</div>

Ehh, actually we have this cruical part in our code, but was unfortunately applied just before the `Range` change. Many thanks for help, it works now!
