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
- Code: Select all
{
//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");
}