# TGraph2D: logarithmic z-axis

**URL:** <https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525>\
**Category:** ROOT\
**Created:** [August 14, 2013, 3:44pm UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525 "2013-08-14T15:44:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmikosch](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@jmikosch](https://root-forum.cern.ch/u/jmikosch)\
**Post date:** [August 14, 2013, 3:44pm UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/1 "2013-08-14T15:44:23Z")

</div>

Hi,

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

```auto
{
  //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");
}
```

 ![](https://root-forum.cern.ch/uploads/default/original/2X/7/72e4b4ad5d1d1c9e5c6a573a5a46697c1b87af28.gif)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 14, 2013, 3:51pm UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/2 "2013-08-14T15:51:20Z")

</div>

You should have an old version of ROOT. With 5.34 on Mac your macro gives me the attached picture.

 ![](https://root-forum.cern.ch/uploads/default/original/2X/7/7f34e17c7d6af8a7ae135f0606aea1a435b7b9ab.png)

---

<div class="post-metadata">

**Author:** ![jmikosch](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@jmikosch](https://root-forum.cern.ch/u/jmikosch)\
**Post date:** [August 14, 2013, 4:05pm UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/3 "2013-08-14T16:05:28Z")

</div>

Thanks, Olivier. I have version 5.26. Looks like time to upgrade…

---

<div class="post-metadata">

**Author:** ![jmikosch](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@jmikosch](https://root-forum.cern.ch/u/jmikosch)\
**Post date:** [August 15, 2013, 4:09am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/4 "2013-08-15T04:09:04Z")

</div>

Hi,

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

```auto
{
  //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");
}
```

 ![](https://root-forum.cern.ch/uploads/default/original/2X/0/09959f5ddd36097ca36ae2197fa35e9fab2ce9b8.gif)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 15, 2013, 7:29am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/5 "2013-08-15T07:29:57Z")

</div>

I see what you mean. The TGraph2D plot uses the whole palette unlike the TH2 which use the correct range of colors. I am investigating.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 15, 2013, 11:15am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/6 "2013-08-15T11:15:13Z")

</div>

This problem is now fixed in 534 and in the trunk.  
With your macro, I now get the attached picture.

 ![](https://root-forum.cern.ch/uploads/default/original/2X/8/82783c1f85facd6c414b5a6351398cf04d91d719.png)

---

<div class="post-metadata">

**Author:** ![jmikosch](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@jmikosch](https://root-forum.cern.ch/u/jmikosch)\
**Post date:** [August 16, 2013, 4:26pm UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/7 "2013-08-16T16:26:52Z")

</div>

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.

Jochen

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 19, 2013, 7:03am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/8 "2013-08-19T07:03:13Z")

</div>

That’s just my job 🙂  
Thanks 🙂

---

<div class="post-metadata">

**Author:** ![HMT](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/9fc29f/32.png) [@HMT](https://root-forum.cern.ch/u/HMT)\
**Post date:** [May 18, 2016, 11:28am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/9 "2016-05-18T11:28:51Z")

</div>

Hi, it seems that this problem comes back in Root 6.07/07.  
I test these codes:

```auto
{
   TCanvas *c = new TCanvas("c","Graph2D example",0,0,600,400);
   Double_t x, y, z, P = 6.;
   Int_t np = 200;
   TGraph2D *dt = new TGraph2D();
   TRandom *r = new TRandom();
   for (Int_t N=0; N<np; 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);
   }
   gStyle->SetPalette(1);
   gPad->SetLogz();
   dt->SetMarkerStyle(20);
   dt->Draw("pcolz");
   return c;
}
```

And get the result as the attached figure.  
Could any one verify this and give me a solution?

Thanks,  
Hieu  
 ![](https://root-forum.cern.ch/uploads/default/original/2X/1/1ba713a6447dcea87f6305673675220d69c61a4c.jpg)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 18, 2016, 11:44am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/10 "2016-05-18T11:44:39Z")

</div>

It might be an other problem because you are not using the same plotting option. I will check.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 18, 2016, 11:50am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/11 "2016-05-18T11:50:25Z")

</div>

> [@](#):
>
> Hi, it seems that this problem comes back in Root 6.07/07.

Can you explain what you think is wrong in the plot you get … seems to me it looks fine …  
I am surely missing something …

---

<div class="post-metadata">

**Author:** ![HMT](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/9fc29f/32.png) [@HMT](https://root-forum.cern.ch/u/HMT)\
**Post date:** [May 19, 2016, 7:00am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/12 "2016-05-19T07:00:32Z")

</div>

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=2_10^(-1). However, on the color palette, the blue color corresponds to z=5_10^(-3).

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

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [May 19, 2016, 7:35am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/13 "2016-05-19T07:35:34Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![HMT](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/9fc29f/32.png) [@HMT](https://root-forum.cern.ch/u/HMT)\
**Post date:** [May 24, 2016, 11:14pm UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/14 "2016-05-24T23:14:37Z")

</div>

I see. I hope that ROOT developers will consider this as a bug to be fixed soon.

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [May 25, 2016, 6:53am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/15 "2016-05-25T06:53:22Z")

</div>

You may open a bug report on [JIRA](https://sft.its.cern.ch/jira/projects/ROOT/summary) in order to keep track of that problem.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 25, 2016, 9:11am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/16 "2016-05-25T09:11:17Z")

</div>

Yes, please a Jira report will help to follow it.

---

<div class="post-metadata">

**Author:** ![HMT](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/9fc29f/32.png) [@HMT](https://root-forum.cern.ch/u/HMT)\
**Post date:** [May 26, 2016, 1:58am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/17 "2016-05-26T01:58:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 26, 2016, 5:48am UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/18 "2016-05-26T05:48:16Z")

</div>

Done:  
[sft.its.cern.ch/jira/browse/ROOT-8200](https://sft.its.cern.ch/jira/browse/ROOT-8200)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 6, 2017, 1:05pm UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/19 "2017-07-06T13:05:35Z")

</div>

Now fixed in master:

```auto
{
   TCanvas *c = new TCanvas("c","Graph2D example",0,0,600,400);
   Double_t x, y, z, P = 6.;
   Int_t np = 200;
   TGraph2D *dt = new TGraph2D();
   TRandom *r = new TRandom();
   for (Int_t N=0; N<np; 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);
   }
   gStyle->SetPalette(1);
   gPad->SetLogz();
   dt->SetMarkerStyle(20);
   dt->Draw("pcolz");
   c->SetPhi(0.00001);
   c->SetTheta(0.00001);
}

```

![](https://root-forum.cern.ch/uploads/default/original/2X/2/2bc3ade6043d86558491837501fa54fc45d13522.png)

---

<div class="post-metadata">

**Author:** ![IzaakWN](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/izaakwn/32/16460_2.png) [@IzaakWN](https://root-forum.cern.ch/u/IzaakWN)\
**Post date:** [June 14, 2018, 9:30pm UTC](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/20 "2018-06-14T21:30:31Z")

</div>

Hi Oliver, I have a this problem how do I find the correct root version with this fix in lxplus? Or, is there way to do a work-around?

[Next page](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525.md?page=2)
