TGraph2D - rebinning axis

Dear ROOTers,

I am trying to rebin the axis of a TGraph2D plot. I need this class because I have an x,y,z dataset, but I need to display it as a 2D map.

The code is the following

b1_map[j-3] = new TGraph2D(4);
b1_map[j-3]->GetXaxis()->Set(4, -180., 180.);
b1_map[j-3]->GetYaxis()->Set(4, -1., 1.);
b1_map[j-3]->SetTitle("; phi [DEG]; cos(theta) [adm]; b1 [adm]");
//filling b1_maps
for (int k = 0; k < 16; k++) //k = all phi and cos(theta) = 4*4
     b1_map[j-3]->SetPoint(k, phi[k], cos_theta[k], b1[k+(j-3)*16]);

but I have 40 bins in each axis. What’s the problem??

Thank you for your time!!

Please read tips for efficient and successful posting and posting code

ROOT Version: 5.34/36
Platform: Windows10
Compiler: VS2015

There is no problem. That’s the Default value. See SetNpx and SetNpy

I don’t know how happened that I haven’t seen that method.
Thank you very much for your time!!

ROOT classes have a lot of methods.
It is easy to miss something.

1 Like

A question arose doing some modifications to the code.
The data I want to plot is 4x4. How does TGraph2D behave if I set a greater binning, perhaps 8x8 or 16x16?
It seems to me it smoothes the results, but I want to ask it to experts.

Thank you again for your patience!

LG, Giammarco

First of all TGraph2D deals with unbinned data. Like TGraph. But it is possible to project these unbinned data on a 2D histogram. The number of bins of this histogram is defined (along X and Y) with SetNpx and SetNpy.

I guess this is the answer to my question: a TGraph2D INTERPOLATES the z axis, therefore if your axis binning is higher than the actual content of the x,y,z array (i.e. > n), interpolation of z is called.

// TGraph2D linearly interpolate a Z value for any (X,Y) point given some

// existing (X,Y,Z) points. The existing (X,Y,Z) points can be randomly

// scattered. The algorithm works by joining the existing points to make

// Delaunay triangles in (X,Y). These are then used to define flat planes

// in (X,Y,Z) over which to interpolate. The interpolated surface thus takes

// the form of tessellating triangles at various angles. Output can take the

// form of a 2D histogram or a vector. The triangles found can be drawn in 3D


The explanation is better in more recent versions of the ROOT reference guide.

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