TGraph2D with a single point

Hi,
I try to use the TGraph2D object but I am running into trouble. To fill a TGraph2D, I access a database and it may happen that I have only one point to draw. In that case, I cannot draw the graph and I have some error message.
Here is a script that shows the problem:

void createTGraph2D(void)
{
const Int_t SIZE = 1;

TGraph2D*  t = new TGraph2D(SIZE);
for ( int i = 0 ; i <SIZE>SetPoint(i, 1. , 2. , 3.);
}

t->Draw(“P”);
}

Then, I have the following message :
Error in : illegal world coordinates range: x1=1.000000, y1=2.000000, x2=1.000000, y2=2.000000
Error in : illegal axis coordinates range: xmin=1.000000, ymin=2.000000, xmax=1.000000, ymax=2.000000
Error in : Error in min-max scope
Error in : Error in min-max scope
Error in : problem setting view
Error in : Error in min-max scope
Error in : illegal world coordinates range: x1=-0.000000, y1=-0.000000, x2=0.000000, y2=0.000000
Error in : illegal axis coordinates range: xmin=-0.000000, ymin=-0.000000, xmax=0.000000, ymax=0.000000

and nothing appears on the screen. I would like to see the point { 1,2,3 } in a arbitrary axis system.

Of course I understand that a single point makes “xmin = xmax” and “ymin = ymax”. How can I plot a TGraph2D with only 1 point ?

I also try to call things like :
void createTGraph2D(void)
{
const Int_t SIZE = 1;

TGraph2D*  t = new TGraph2D(SIZE);

t->GetXaxis()->SetRangeUser(0,5);
t->GetYaxis()->SetRangeUser(0,5);
t->GetZaxis()->SetRangeUser(0,5);

for ( int i = 0 ; i <SIZE>SetPoint(i, 1. , 2. , 3.);
}

t->Draw("P");

}

but it has no effect.

I am using root 5.11-06 on a linux box with gcc 4.

thanks a lot for your attention

Pierre

Hi Pierre,
yuo forgot TAxis::SetLimits(min, max)

{
  TGraph2D* t = new TGraph2D(1);
  t->SetPoint(0, 1. , 2. , 3.);
  
  t->GetXaxis()->SetLimits(0, 2);
  t->GetYaxis()->SetLimits(1, 3);
  t->GetZaxis()->SetLimits(2, 4);
  
  //  t->GetXaxis()->SetRangeUser(0, 2);
  //  t->GetYaxis()->SetRangeUser(1, 3);
  t->GetZaxis()->SetRangeUser(2, 4);
  
  t->Draw("P0");
}

Hope this help, Jan

You can also try to define the 2D histogram used by TGraph2D via:

TGraph2D::SetHistogram()

Thanks ! It work fine know !

Best reagards,
Pierre