# TGraph2D Plotting Issues

**URL:** <https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562>\
**Category:** ROOT\
**Tags:** graphics\
**Created:** [October 12, 2017, 7:01pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562 "2017-10-12T19:01:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [October 12, 2017, 7:01pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/1 "2017-10-12T19:01:10Z")

</div>

Hi All,

I am doing some testing with `TGraph2D` objects and have run into some issues. The first issue appears after drawing the `TGraph2D` with the `LINE` option, when one tries to rotate the figure using the mouse on the canvas a segmentation fault is thrown. This occurred originally in the following python script, but I found it also happens in a C++ script as well. This bug appears in the latest 6.11.02 release.

The error message:

```auto
$ root TGraph2D.C
root [0] 
Processing TGraph2D.C...
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [1] root.exe(40685,0x7fff9e670340) malloc: *** error for object 0xbfa66083c0c91240: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

```

The python script:

```python
import numpy as np
import ROOT

num_pnts = 20

radius = 10E3
phi = np.radians(90)
theta = np.radians(np.array(range(num_pnts), dtype=np.float64) / num_pnts * 360.)

x = radius * np.sin(theta) * np.cos(phi)
y = radius * np.sin(theta) * np.sin(phi)
z = radius * np.cos(theta)

g = ROOT.TGraph2D(num_pnts, x, y, z)
g.Draw("LINE")
ROOT.gPad.Update()
raw_input("WAIT")

```

Transcribed to C++:

```cpp
{
   const int num_pnts = 20;
   double radius = 10E3;
   double phi = 90 * TMath::DegToRad();
   double theta[num_pnts];
   double x[num_pnts], y[num_pnts], z[num_pnts];

   for (int i=0;i<num_pnts;i++) {
      theta[i] = (double) i / num_pnts * 360. * TMath::DegToRad();
      x[i] = radius * sin(theta[i]) * cos(phi);
      y[i] = radius * sin(theta[i]) * sin(phi);
      z[i] = radius * cos(theta[i]);
   }

   TGraph2D *g = new TGraph2D(num_pnts, x, y, z);
   g->Draw("LINE");
}

```

In addition, When trying to plot the `TGraph2D` n a juypter notebook I am greeted with the following message:

```auto
Warning in <TROOT::Append>: Replacing existing TGraph2D: Graph2D (Potential memory leak).
The canvas contains an object of a type jsROOT cannot currently handle (TGraph2D). Falling back to a static png.

```

Is there a timeline on when this functionality may be incorporated? I assume it is similar to that of plotting `TH2` objects with options like `SURF`.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [October 12, 2017, 7:17pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/2 "2017-10-12T19:17:56Z")

</div>

Hi,

TGraph2D is already supported in JSROOT

[https://root.cern/js/latest/examples.htm#tgraph2d](https://root.cern/js/latest/examples.htm#tgraph2d)

It simply should be enabled in Jupyter.  
Probably, @etejedor can help you

Regards, Sergey

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [October 12, 2017, 8:49pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/3 "2017-10-12T20:49:31Z")

</div>

> [@linev](#):
>
> TGraph2D is already supported in JSROOT
> 
> [JavaScript ROOT examples](https://root.cern/js/latest/examples.htm#tgraph2d)

Excellent! I’ll keep my fingers crossed that this is easy to include in Jupyter.

---

<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:** [October 13, 2017, 7:22am UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/4 "2017-10-13T07:22:27Z")

</div>

> [@ksmith](#):
>
> Transcribed to C++:

I am looking at it . Thanks for reporting.

---

<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:** [October 13, 2017, 7:45am UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/5 "2017-10-13T07:45:49Z")

</div>

I verified that it does not crash with 6.10. But anyway the picture I get is the same and is a bit weird… (to say the less…) I think it comes for the fact all the points are in the same plane. I am investigating.

 ![08](https://root-forum.cern.ch/uploads/default/original/2X/7/77594562aa45d506f2493310fc77fad3c25f9e25.jpg)

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [October 13, 2017, 7:53am UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/6 "2017-10-13T07:53:02Z")

</div>

Hi,

From what version is TGraph2D supported in JSROOT? It is easy to make it available for Jupyter (and SWAN) if it’s not already, just a matter of making a link point to it.

Cheers,

Enric

---

<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:** [October 13, 2017, 8:21am UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/7 "2017-10-13T08:21:15Z")

</div>

@ksmith you are working on Mac with the Cocoa backend ? right ?

---

<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:** [October 13, 2017, 8:28am UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/8 "2017-10-13T08:28:21Z")

</div>

Yes it is due to the fact the points are all in the same plane. If after the loop I add:

```auto
x[1]=10;

```

Then it does not crash.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [October 13, 2017, 8:41am UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/9 "2017-10-13T08:41:58Z")

</div>

> [@etejedor](#):
>
> From what version is TGraph2D supported in JSROOT? It is easy to make it available for Jupyter (and SWAN) if it’s not already, just a matter of making a link point to it.

Since a JSROOT 4.8 (December 2016)

> **[Release 4.8.0 · root-project/jsroot](https://github.com/root-project/jsroot/releases/tag/4.8.0)**
>
> Many improvements in the I/O part
> 
> support most of STL containers
> support TMap and TClonesArray containers
> all kind of multidimensional arrays
> correct treatment of foreign classes
> supports differen...

I guess, we should update list of supported classes in Jupyter.

Regards,  
Sergey

---

<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:** [October 13, 2017, 1:20pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/10 "2017-10-13T13:20:34Z")

</div>

> [@ksmith](#):
>
> when one tries to rotate the figure using the mouse on the canvas a segmentation fault is thrown.

This is now fixed in the ROOT master. Thanks to have seen it.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [October 16, 2017, 3:09pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/11 "2017-10-16T15:09:49Z")

</div>

> [@couet](#):
>
> This is now fixed in the ROOT master. Thanks to have seen it.

Thanks for the quick fix. I’ve tested it on Cocoa back end and it is working.

> [@linev](#):
>
> I guess, we should update list of supported classes in Jupyter.

Seems like it is quite out of date indeed. I’ve updated the list of supported jsROOT drawables:

> <https://github.com/root-project/root/pull/1191>
>
> Used the jsROOT examples page, https://root.cern/js/latest/examples.htm,
> to det…ermine if the drawables were supported.

Unfortunately, the draw type I wanted “LINE” is not yet supported. Might this be a future development?

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [October 16, 2017, 3:37pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/12 "2017-10-16T15:37:49Z")

</div>

Hi,

> [@ksmith](#):
>
> Unfortunately, the draw type I wanted “LINE” is not yet supported. Might this be a future development?

Yes, LINE was not supported.  
I recognize this one I saw your message.  
It is supported now in dev version, will be available for Jupyter in next few weeks:

> **[JSROOT examples](https://jsroot.gsi.de/dev/examples.htm#tgraph2d_line)**
>
> Web page shows supported ROOT classes and correspondent draw options

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [October 16, 2017, 3:40pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/13 "2017-10-16T15:40:42Z")

</div>

> [@linev](#):
>
> It is supported now in dev version, will be available for Jupyter in next few weeks:
> 
> [JavaScript ROOT examples](http://jsroot.gsi.de/dev/examples.htm#tgraph2d_line)

You even used the hard case from above. Looks good, thanks for the quick work on this.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [October 30, 2017, 3:40pm UTC](https://root-forum.cern.ch/t/tgraph2d-plotting-issues/26562/14 "2017-10-30T15:40:42Z")

</div>

Closed on October 30, 2017, 3:40pm UTC

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