TGraph2D Plotting Issues

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:

$ 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:

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++:

{
   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:

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.

Hi,

TGraph2D is already supported in JSROOT

https://root.cern/js/latest/examples.htm#tgraph2d

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

Regards, Sergey

1 Like

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

I am looking at it . Thanks for reporting.

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.

1 Like

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

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

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

x[1]=10;

Then it does not crash.

Since a JSROOT 4.8 (December 2016)

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

Regards,
Sergey

1 Like

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

1 Like

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

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

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

Hi,

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:

1 Like

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

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