Potential Bug in TGraph2D


ROOT Version:6.13/01
Platform: OSX 10.12
Compiler: default

Hey Rooters,
I ran into a wierd issue when attempting to plot a TGraph2D with one of the coordinates being negative and planar.
For example

TGraph2D* graph()
{
  TGraph2D* graph = new TGraph2D(1000);
  for(int iP = 0; iP < 1000;iP ++)
  {
    graph->SetPoint(iP,rand()%10/10.0,-5,rand()%10/10.0);
  }
  return graph;
}

Leads to an unsightly dump when trying to draw (see below). It looks like the range is being bumped in magnitude not value. Ie it’s trying to make ymin > ymax.
Thoughts?

root [1] b = graph()
(TGraph2D *) 0x7fc3facc35b0
root [2] b->Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
Error in <TCanvas::Range>: illegal world coordinates range: x1=-0.112500, y1=-4.937500, x2=1.012500, y2=-5.062500
Error in <TCanvas::RangeAxis>: illegal axis coordinates range: xmin=0.000000, ymin=-4.950000, xmax=0.900000, ymax=-5.050000
Error in <TView3D::ResetView>: Error in min-max scope
Error in <TView3D::ResetView>: Error in min-max scope
Error in <TView3D::ResetView>: Error in min-max scope
Error in <TView3D::SetRange>: problem setting view
Error in <TView3D::ResetView>: Error in min-max scope

It is because your Y axis has a nul range (all the points at the same Y value).

try:

{
  TGraph2D* graph = new TGraph2D(1000);
    graph->SetPoint(0,0.,0.,0.);;

  for(int iP = 1; iP < 1000;iP ++)
  {
    graph->SetPoint(iP,rand()%10/10.0,-5,rand()%10/10.0);
  }
  graph->Draw("P0");
}

Hey Couet,

Thanks for the prompt reply. I recognize it is because the data are planar. In the case where the axis is positive the range is automatically taken as a small delta around the plane and a reasonable view is generated.
For example with

TGraph2D* graph()
{
  TGraph2D* graph = new TGraph2D(1000);
  for(int iP = 0; iP < 1000;iP ++)
  {
    graph->SetPoint(iP,rand()%10/10.0,5,rand()%10/10.0);
  }
  return graph;
}

the range is set to ymin = 4.95 ymax = 5.05
and the resultant call to draw is meaningful
ie it produces
image

But with the negative case, the automatic change to the range is in magnitude from zero, not in absolute value.
ie ymin = -4.95 ymax = -5.05 and the axis range is invalid. I’m guessing this isn’t the desired behavior, as I would hope it would behave the same regardless of whether the plane was positive or negative?

I can obviously fudge it to get a reasonable plot.

Try to set ymax > ymin (also for negative values).

Hey Wile_E_Coyote,

I’m not setting the range. It seems like unanticipated behavior. For example,

TGraph2D* produceWorkingGraph()
{
  TGraph2D* graph = new TGraph2D(1000);
  for(int iP = 0; iP < 1000;iP ++)
  {
    graph->SetPoint(iP,rand()%10/10.0,5,rand()%10/10.0);
  }
  return graph;
}


TGraph2D* produceNotWorkingGraph()
{
  TGraph2D* graph = new TGraph2D(1000);
  for(int iP = 0; iP < 1000;iP ++)
  {
    graph->SetPoint(iP,rand()%10/10.0,-5,rand()%10/10.0);
  }
  return graph;
}

TGraph2D* a = produceWorkingGraph();
TGraph2D* b = produceNotWorkingGraph();
//no error
a->Draw("p0");
//range error
b->Draw("p0");

The range is being generated within the class, and in the negative case, the range is invalid.
Does this not feel like unanticipated behavior?

It seems @couet is going to have some fun again.

It seems I will …

Now fixed in the master. The problem was also along the X axis. The following macro now works (see output).

{
   TGraph2D* graph = new TGraph2D(1000);
   for (int iP = 0; iP < 1000;iP ++) graph->SetPoint(iP,-5,-5,rand()%10/10.0);
   graph->Draw("P0");
}

Thanks to have seen and reported the problem.

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