# TF1 disappears if canvas outside range

**URL:** <https://root-forum.cern.ch/t/tf1-disappears-if-canvas-outside-range/43355>\
**Category:** ROOT\
**Tags:** graphics, bug\
**Created:** [February 1, 2021, 3:45pm UTC](https://root-forum.cern.ch/t/tf1-disappears-if-canvas-outside-range/43355 "2021-02-01T15:45:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [February 1, 2021, 3:45pm UTC](https://root-forum.cern.ch/t/tf1-disappears-if-canvas-outside-range/43355/1 "2021-02-01T15:45:25Z")

</div>

If a user attempts to draw a `TF1` that is undefined in part of its range, it is drawn as a flat line at 0 without throwing an error. If 0 is outside the Yaxis range, the user is left with no graphics and no error to help them debug. Reproducer follows.

It would be nice if drawing an undefined value raised an error.

* * *

```python
import ROOT as r
# define coordinates
# note that 0 is outside the Yaxis range
h = r.TH2F("h", "h", 100, 1, 101, 100, 0, 100)
h.Draw()
# declare function that evaluates to NaN in part of its range
f = r.TF1("f", "sqrt(50 - x) * 10", 0, 100)
f.Draw("same")
# f is not shown and no error is raised

```

* * *

_ROOT Version:_ 6.22/06  
_Platform:_ macOS  
_Compiler:_ conda-forge

* * *

---

<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:** [February 1, 2021, 4:35pm UTC](https://root-forum.cern.ch/t/tf1-disappears-if-canvas-outside-range/43355/2 "2021-02-01T16:35:46Z")

</div>

You are right, the error shows with:

```auto
root [0] auto f = new TF1("f", "sqrt(50 - x) * 10", 0, 100);
root [1] f->Draw()
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

```

But not with:

```auto
void mw()
{
   auto h = new TH2F("h", "h", 100, 1, 101, 100, 0, 100);
   h->Draw();
   auto f = new TF1("f", "sqrt(50 - x) * 10", 0, 100);
   f->Draw("same");
}

```

---

<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:** [February 15, 2021, 4:36pm UTC](https://root-forum.cern.ch/t/tf1-disappears-if-canvas-outside-range/43355/3 "2021-02-15T16:36:12Z")

</div>

Closed on February 15, 2021, 4:36pm UTC

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