# Cannot make a TGraph2D plot

**URL:** <https://root-forum.cern.ch/t/cannot-make-a-tgraph2d-plot/9527>\
**Category:** ROOT\
**Created:** [January 23, 2010, 12:22am UTC](https://root-forum.cern.ch/t/cannot-make-a-tgraph2d-plot/9527 "2010-01-23T00:22:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhiyiliu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/85e7bf/32.png) [@zhiyiliu](https://root-forum.cern.ch/u/zhiyiliu)\
**Post date:** [January 23, 2010, 12:22am UTC](https://root-forum.cern.ch/t/cannot-make-a-tgraph2d-plot/9527/1 "2010-01-23T00:22:59Z")

</div>

Hi,  
I am trying to plot 4 points with lines connected. I use the following code:

```auto
  double *x = new double[4];
  double *y = new double[4];
  double *z = new double[4];
  x[0] = 6215.736328;
  x[1] = 5542.363770;
  x[2] = 5518.736816;
  x[3] = 5518.736816;

  y[0] = 3853.795410;
  y[1] = 5270.174805;
  y[2] = 5329.190430;
  y[3] = 5329.190430;
  
  z[0] = 2723.959961;
  z[1] = 2723.959961;
  z[2] = 2723.959961;
  z[3] = 2723.959961;
  
  TGraph2D * g = new TGraph2D(4, x, y, z);

  g->Draw("LINE");
```

However, I was given errors like:

> [@](#):
>
> 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  
> Error in TCanvas::Range: illegal world coordinates range: x1=-0.000000, y1=-0.000000, x2=0.000000, y2=0.000000  
> Error in TCanvas::RangeAxis: illegal axis coordinates range: xmin=-0.000000, ymin=-0.000000, xmax=0.000000, ymax=0.000000

the problem seems from the Z values. Maybe all points are in the same plane? so I do not know why I cannot plot the points even they are in the same plane. any hint?

Thanks,  
Zhiyi.

---

<div class="post-metadata">

**Author:** ![lixo1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/aeb1de/32.png) [@lixo1](https://root-forum.cern.ch/u/lixo1)\
**Post date:** [January 23, 2010, 8:59pm UTC](https://root-forum.cern.ch/t/cannot-make-a-tgraph2d-plot/9527/2 "2010-01-23T20:59:11Z")

</div>

Hi, I tried to plot it first using g-\>Draw(); and them g-\>Draw(“LINE”); and I get the following image (see below).

 ![](https://root-forum.cern.ch/uploads/default/original/2X/0/0369c6ffdda69b3492a47458361a6f68e837a571.gif)

---

<div class="post-metadata">

**Author:** ![zhiyiliu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/85e7bf/32.png) [@zhiyiliu](https://root-forum.cern.ch/u/zhiyiliu)\
**Post date:** [January 23, 2010, 9:02pm UTC](https://root-forum.cern.ch/t/cannot-make-a-tgraph2d-plot/9527/3 "2010-01-23T21:02:45Z")

</div>

Interesting. Thanks for this little trick. 🙂

Which root version are you using? I tried your approach in

root\_v5.26  
root\_v5.23  
root\_v5.20

. All of them give me the same error that I posted above.

Cheers,  
Zhiyi.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 25, 2010, 10:04am UTC](https://root-forum.cern.ch/t/cannot-make-a-tgraph2d-plot/9527/4 "2010-01-25T10:04:22Z")

</div>

Yes, you get these errors because the Z values are all the same. I will fix that. If you only want to draw a line you do not need a TGraph2D. TGraph2D are not meant to be used that way (see the doc). Nevertheless what you tried should work and, as I said, I will fix it. Meanwhile I would suggest you use 3D polyline as it is what you are looking for:

```auto
{
   double *x = new double[4];
   double *y = new double[4];
   double *z = new double[4];
   x[0] = 6215.736328;
   x[1] = 5542.363770;
   x[2] = 5518.736816;
   x[3] = 5518.736816;

   y[0] = 3853.795410;
   y[1] = 5270.174805;
   y[2] = 5329.190430;
   y[3] = 5329.190430;

   z[0] = 2723.959961;
   z[1] = 2723.959961;
   z[2] = 2723.959961;
   z[3] = 2723.959961;

   TPolyLine3D *line3D = new TPolyLine3D (4,x,y,z) ;

   TH2F* histo = new TH2F("histo","", 1,5518.,6216.,1,3853.,5330.) ;
   histo->SetStats(kFALSE) ;
   histo->SetMinimum(2723.959960) ;
   histo->SetMaximum(2723.959962) ;

   TCanvas *canvas = new TCanvas("canvas","canvas",0,0,1000,618) ;
   canvas->SetFrameFillColor(30);
   canvas->SetTheta(23.) ; canvas->SetPhi(-23.) ;
   gPad->SetLeftMargin(0.18) ;
   gPad->SetRightMargin(0.10) ;
   gPad->SetTopMargin(0.20) ;
   gPad->SetBottomMargin(0.20) ;

   histo->Draw("lego0,fb") ;
   line3D->Draw() ;
}
```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 25, 2010, 10:47am UTC](https://root-forum.cern.ch/t/cannot-make-a-tgraph2d-plot/9527/5 "2010-01-25T10:47:51Z")

</div>

This is now fixed in the SVN trunk.  
[root.cern.ch/viewvc?view=rev&revision=32105](http://root.cern.ch/viewvc?view=rev&revision=32105)  
thanks for reporting.
