TF1 disappears if canvas outside range

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.


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


You are right, the error shows with:

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:

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");
}
1 Like

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