# TGraph2D and surf draw option

Hello,

I’m trying to make some nice 2D plots with surf1 option but it still doesn’t behave as I’d expect. I know about the SetNpx trick already but still… Please look at the sample code.

``````#include "TGraph2D.h"

void bug()
{
Double_t X, Y, Z;

Int_t M = 0;
for (Double_t x = 0.; x < 10.; x += 1.) {
for (Double_t y = 0.; y < 10.; y += 1.) {
X[M] = x;
Y[M] = y;
Z[M] = (x-5)*(x-5) + (y-5)*(y-5);
M++;
}
}

TGraph2D *g2d = new TGraph2D(M, X, Y, Z);
g2d->SetNpx(41); g2d->SetNpy(42);
g2d->Draw("surf1");
}``````

This draws nice paraboloid but unfortunately with jump at x=y=0. The only way to remove the jump that I’ve found, is to use mouse and set Npx and Npy several times again. But this is a bit tedious and destroys axis labels all the time.

Kaspi.

As you already know about the npx/y trick I will not propose it again. Unfortunately I have nothing else to propose right now. I am trying to fix this. I’ll let you know when done.

By the way why don’t you use the specific TGraph2D option “TRI1” instead of SURF1 ?
It draws directly the triangles produced by the Delaunay’s algorithm which is the base of TGraph2D …

Hello, thanks for quick reply. The surfaces I plot are quite complicated and I find them look better when surf1 is used. The 2nd reason is I’m interested in minimae, so I usually cut the graph just a bit above the minimum. Within tri1 the cut plain is drawn with many colors (really don’t know why) and it confuses the relevant part of the plot (the code bellow shows it). With surf1 the cut plain is just in one color. Or is there a way how not to show the cut plain at all? I’d prefer this the best. I’m really grateful for any advices. Thanks,

Kaspi

``````#include "TGraph2D.h"

void bug()
{
Double_t X, Y, Z;

Int_t M = 0;
for (Double_t x = 0.; x < 10.; x += 1.) {
for (Double_t y = 0.; y < 10.; y += 1.) {
X[M] = x;
Y[M] = y;
Z[M] = (x-5)*(x-5) + (y-5)*(y-5);
M++;
}
}

TGraph2D *g2d = new TGraph2D(M, X, Y, Z);
g2d->SetNpx(41); g2d->SetNpy(41);
g2d->GetZaxis()->SetRangeUser(0., 10.);
g2d->Draw("tri1");
}``````

I will look at this too. Thanks !

The problem with SURF1 is now fixed in the CVS head.

Thak you very much Kaspi