Bad range setting for TF2 drawn with "same"

Hello,

I’ve encountered a problem recently. I don’t recall it in the past versions of root, but maybe it was there. It seems that TF2 drawn on top of TGraph2D does not adjust it ranges to the TGraph2D ranges, but thinks it is drawn over it’s original ranges. This is a sample code of a cone drawing and fitting:

auto g = new TGraph2D();

for(int x=0; x<100; ++x)
	for(int y=0; y<100; ++y)
		g->SetPoint(g->GetN(), x+50, y+50, sqrt(x*x+y*y)/2+10);

g->Draw("P0");

auto f5 = new TF2("f5", "sqrt((x-[0])^2+(y-[1])^2)/[2]+[3]", 0, 150, 0, 150);
f5->SetParameters(10, 0, 1, 0);
//f5->SetRange(0,0,150,150);
g->Fit(f5);
f5->Draw("same surf");

You can see that even though the function fits perfectly and should cover the points of the graph exactly, it is shifted. If I draw the function first, and then the TGraph2D on top of it, the graph adapts axes properly.

Perhaps it is just a missing feature, that I somehow have not missed before…

Btw. would you mind adding a method for TGraph and TGraph2D that calls SetPoint(this->GetN()…)? For me, and probably not only me, adding single points one by one is the most common scenario, so a method, for example AddPoint(x,y, (z)) that calls SetPoint(this->GetN(), x, y, (z)) would be really helpful.


ROOT Version: 6.22
Platform: Fedora 30
Compiler: Not Provided


The “SAME” option for 3D plots (LEGO SURFACE) as a limitation (because the 3D space used is in fine normalised): the plots should have the same ranges. So do:

auto f5 = new TF2("f5", "sqrt((x-[0])^2+(y-[1])^2)/[2]+[3]", 50, 150, 50, 150);

Yes it makes sense, that would allow to add a point without taking into account the index, just append one point …

This PR https://github.com/root-project/root/pull/6688 add the AddPoint Method.

Thanks for adding the AddPoint()!

About the “same” in “lego/surf” - I see. I can change the TF2 function manually with SetRange. However, can’t this be invoked automaticaly when TF2 (or TH2) ::Draw() is called, reading the ranges from the pad?

You mean if we plot a TF2 with option same as lego or surface make sure the ranges are mapped to the already existing plot ? That can be check, we do something similar with SAME and BOX. I am not sure that can be done but we can check.

Yes, that’s what I mean. It would make the behaviour consistent with other drawing options. Thanks!

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