I’d like to plot a TGraph2D with a logarithmic z-axis. TPad::SetLogz() will set the z-axis to log-scale and adjust the TPaletteAxis, but the color palette does not translate to the graph. It works for TH2F though. You can see this from the following example, which is derived from the standard example in the TGraph2D documentation.

Any idea what is going on here and how to fix it?

Thanks,
Jochen

{
//logarithmic z-axis - color palette:
//it works for TH2F but not for TGraph2D
TCanvas *c = new TCanvas("c","Graph2D example",0,0,600,800);
c->Divide(1,2);
c_1->SetLogz();
c_2->SetLogz();
Double_t x, y, z, P = 6.;
Int_t np_g = 200;
Int_t np_h = 20000;
TGraph2D *dt = new TGraph2D();
TH2F *h = new TH2F("TH2F","TH2F",50,-6,6,50,-6,6);
TRandom *r = new TRandom();
for (Int_t N=0; N<np_g; N++) {
x = 2*P*(r->Rndm(N))-P;
y = 2*P*(r->Rndm(N))-P;
z = (sin(x)/x)*(sin(y)/y)+0.2;
dt->SetPoint(N,x,y,z);
}
for (Int_t N=0; N<np_h; N++) {
x = 2*P*(r->Rndm(N))-P;
y = 2*P*(r->Rndm(N))-P;
z = (sin(x)/x)*(sin(y)/y)+0.2;
h->Fill(x,y,z);
}
gStyle->SetPalette(1);
h->SetStats(0);
//h->GetZaxis()->SetRangeUser(1e-3,5);
//dt->GetZaxis()->SetRangeUser(1e-3,5);
c->cd(1);
dt->Draw("tri1z");
c->cd(2);
h->Draw("surf2z");
}

I have upgraded to the current ROOT version v5.34 as suggested. Unfortunately, I am running into a related problem now. The command TGraph2D::GetZaxis()->SetRangeUser(a,b) is ignored in the macro. Adjusting the axis “by hand” afterwards in the TPad works, but once again the color palette does not translate to the graph. Similarly, if I use TGraph2D::SetMinimum(a) and TGraph2D::SetMaximum(b) in the macro, the z-axis and the TPaletteAxis is adjusted, but it does not translate to the graph. See for macro and plot below.

The reason I want to do this is to have two TGraph2Ds back to back with the same z-axis range for better comparison.

Thanks,
Jochen

{
//logarithmic z-axis - color palette:
//it works for TH2F but not for TGraph2D
TCanvas *c = new TCanvas("c","Graph2D example",0,0,600,800);
c->Divide(1,2);
c_1->SetLogz();
c_2->SetLogz();
Double_t x, y, z, P = 6.;
Int_t np_g = 200;
Int_t np_h = 20000;
TGraph2D *dt = new TGraph2D();
TH2F *h = new TH2F("TH2F","TH2F",50,-6,6,50,-6,6);
TRandom *r = new TRandom();
for (Int_t N=0; N<np_g; N++) {
x = 2*P*(r->Rndm(N))-P;
y = 2*P*(r->Rndm(N))-P;
z = (sin(x)/x)*(sin(y)/y)+0.2;
dt->SetPoint(N,x,y,z);
}
for (Int_t N=0; N<np_h; N++) {
x = 2*P*(r->Rndm(N))-P;
y = 2*P*(r->Rndm(N))-P;
z = (sin(x)/x)*(sin(y)/y)+0.2;
h->Fill(x,y,z);
}
gStyle->SetPalette(1);
h->SetStats(0);
h->GetZaxis()->SetRangeUser(1e-3,1e3);
//dt->GetZaxis()->SetRangeUser(1e-3,1e3); //this command is ignored
dt->SetMaximum(1e3);
dt->SetMinimum(1e-3);
c->cd(1);
dt->Draw("tri1z");
c->cd(2);
h->Draw("surf2z");
}

Thanks a lot Olivier for the excellent support! I am very impressed with the promptness of your replies and the fix. I managed to get my plot done with the trunk version obtained from git.

You can see there is a mismatch between the colors of points and the color’s z-values.
For example, in the 3D graph, the blue points correspond to z=210^(-1). However, on the color palette, the blue color corresponds to z=510^(-3).

If you plot this graph in linear scale of z. Such thing does not happen.

Both ROOT 5.34/36 and 6.06/04 behave the same way.
The graph is drawn with log-z but the color is still linear-z (improperly shown in the palette’s axis as being log, too).

I don’t have a CERN account to create a bug report in Jira. It seems that an external light weight account that I created doesn’t work.
Can any one of you help to create such bug report?
Thanks.