Drawing TGraph2D with TF2?

From: Matthew Strait <strait_at_physics.umn.edu>
Date: Fri, 17 Aug 2007 12:47:04 -0500 (CDT)


I want to draw a 3D scatter plot together with a fit plane. Here's a very simple macro that should do that:

{

   TF2 aplane("aplane", "1+2*x-y", -10, 10, -10, 10);

   TGraph2D somedata;

   somedata.SetPoint(0, 0, 0, 1); // should be on plane
   somedata.SetPoint(1, 1, 1, 2); // ditto
   somedata.SetPoint(2, 2, 1, 4); // ditto
   somedata.SetPoint(3, 1, 2, 1); // ditto
   somedata.SetPoint(4, 5, 5, -4); // One off the plane

   aplane.Draw("surf");
   somedata.Draw("same p0");
}

But the points are not drawn correctly. It appears that the TF2 and the TGraph2D each have their own set of axes which are scaled differently, but only whichever is drawn first gets displayed. The corresponding thing in 2D works just fine:

{

   TF1 aline("aline", "1+2*x", -10, 10);

   TGraph somedata;

   somedata.SetPoint(0, 0, 1); // should be on line
   somedata.SetPoint(1, -1, -1); // ditto
   somedata.SetPoint(2, 3, 7); // ditto
   somedata.SetPoint(3, 2, 1); // should be *off* the line

   somedata.Draw("AP*");
   aline.Draw("SAME");
}

I have found no way to get the TF2 and TGraph2D to display properly together. Is there a way? (One that doesn't involve kludgy fine tuning on a plot by plot basis, I mean!)

I could not find anywhere in the documentation that suggests that this shouldn't work or that it requires anything more complicated than in the lower-dimensional case. It would be nice if something could be added to this effect.

Thanks,
Matthew Received on Fri Aug 17 2007 - 19:47:18 CEST

This archive was generated by hypermail 2.2.0 : Fri Aug 17 2007 - 23:50:02 CEST