# Problems with TGraph2D and pcol (and zcol)

**URL:** <https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595>\
**Category:** ROOT\
**Created:** [June 14, 2011, 9:05pm UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595 "2011-06-14T21:05:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![roodman](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/9fc29f/32.png) [@roodman](https://root-forum.cern.ch/u/roodman)\
**Post date:** [June 14, 2011, 9:05pm UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/1 "2011-06-14T21:05:25Z")

</div>

I have been using TGraph2Ds to visualize a set of points, but am seeing several problems when viewing  
them with both the pcol and zcol options. I am using 5.28.00b.

Using the following snippet

```auto
Double_t dz[10] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.};
Double_t x[10] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.};
Double_t y[10] = {.4,.5,.1,.3,.8,.4,.5,.6,.2,.1};
TGraph2D hgdzval("hgdzval","dzval",10,x,y,dz);
hgdzval.Draw("zcolpcol");
```

I get the following image  
[c1a.pdf](https://root-forum.cern.ch/uploads/default/original/2X/d/d63931f186d52d12fa92cc240687d0643dd3bfd1.pdf) (15.2 KB)

Problem 1: the colors don’t show up on the Z color scale

Playing around I tried  
hgdzval.Draw(“zcol”) and then after that another time with hgdzval.Draw(“zcolpcol”)  
Now the z color scale shows the colors:  
[c1b.pdf](https://root-forum.cern.ch/uploads/default/original/2X/a/a9f2223fccb28df43bc2d19cc28532f8a44c52d2.pdf) (15.2 KB)

Problem 2: By default the z color scale is located off the edge of the pad. Perhaps it is possible to resize  
parts of the pad so the color scale is all visible, but it would be very nice if the root defaults made that so.  
I checked that I’m not changing any of the pad margins in my rootlogon, by the way.

Problem 3: Another issue is that it doesn’t seem to be possible to resize the histogram frame interactively,  
with a TGraph2D - I can’t see where to “grab” onto it in the pad, you always get the icon to rotate the frame.

Lastly, I moved the z color scale to where I can see it, and now I want to rescale it. What I hoped would happen is that if I interactively zoom on the z color scale, that the colors would remap to the new limits  
and that the color on the points would also rescale. This would be very useful behavior. But what happens looks buggy.

Problem 4: The z-axis on the frame changes correctly, and the numbers on the z color change, but the colors on the points don’t remap, and the colors on the z color scale are confused. See:[c1c.pdf](https://root-forum.cern.ch/uploads/default/original/2X/b/b6d1648b8da88472117dec7664ebab2d303f769e.pdf) (15.1 KB)

Once this is fixed it would also be handy to adjust the color zoom by a script - how is that done with a TGraph2D?

The pcol option is potentially very useful - so thanks much for your help in addressing these issues.

Aaron

---

<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:** [June 15, 2011, 9:16am UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/2 "2011-06-15T09:16:02Z")

</div>

To get the right palette simply do:

hgdzval.GetHistogram()-\>SetContour(10);

---

<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:** [June 15, 2011, 11:57am UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/3 "2011-06-15T11:57:43Z")

</div>

I will make this contours level definition automatic.

---

<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:** [June 15, 2011, 1:11pm UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/4 "2011-06-15T13:11:41Z")

</div>

> [@](#):
>
> Problem 1: the colors don’t show up on the Z color scale

I will post the fix soon.

> [@](#):
>
> Problem 2: By default the z color scale is located off the edge of the pad.

You can change the right margin. The new " Modern" style does it better by default.

> [@](#):
>
> Problem 3: Another issue is that it doesn’t seem to be possible to resize the histogram frame interactively,  
> with a TGraph2D.

That’s the same with histo plotted lego and surface. you can do it with a script.

> [@](#):
>
> Lastly, I moved the z color scale to where I can see it, and now I want to rescale it. What I hoped would happen is that if I interactively zoom on the z color scale, that the colors would remap to the new limits  
> and that the color on the points would also rescale. This would be very useful behavior. But what happens looks buggy.

I agree.

---

<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:** [June 15, 2011, 1:34pm UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/5 "2011-06-15T13:34:28Z")

</div>

> [@](#):
>
> Lastly, I moved the z color scale to where I can see it, and now I want to rescale it. What I hoped would happen is that if I interactively zoom on the z color scale, that the colors would remap to the new limits  
> and that the color on the points would also rescale. This would be very useful behavior. But what happens looks buggy.

it is because the palette as been primarily implement for histograms with option col or surf1 and for these options the palette is always remapped from the lowest color to the highest in the palette (after a zoom)…

---

<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:** [June 16, 2011, 8:07am UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/6 "2011-06-16T08:07:33Z")

</div>

> [@](#):
>
> Problem 1: the colors don’t show up on the Z color scale

Now fixed.

---

<div class="post-metadata">

**Author:** ![roodman](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/9fc29f/32.png) [@roodman](https://root-forum.cern.ch/u/roodman)\
**Post date:** [February 8, 2012, 9:29pm UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/7 "2012-02-08T21:29:05Z")

</div>

I am trying again to use TGraph2Ds with the pcol option, now with ROOT 5.32/00

The script I previously posted gives correct results - the colors scale match the colors used for the markers - see the first attachment.

[pcol-example1.pdf](https://root-forum.cern.ch/uploads/default/original/2X/3/36eebbdcfff090ed4875d7d6eba2d78ce0e7dcbb.pdf) (15.5 KB)

However, if I change the z-axis minimum or maximum, either with the cursor or by .SetMinimum and .SetMaximum the marker colors don’t match the scale, see the second attachment.

[pcol-example2.pdf](https://root-forum.cern.ch/uploads/default/original/2X/d/db1c072c82d46e0590265b9cf631ec4342e2df3c.pdf) (15.1 KB)

Here is what I did:

Double\_t dz[10] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.};  
Double\_t x[10] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.};  
Double\_t y[10] = {.4,.5,.1,.3,.8,.4,.5,.6,.2,.1};  
TGraph2D hgdzval(“hgdzval”,“dzval”,10,x,y,dz);  
hgdzval.Draw(“zcolpcol”);  
hgdzval.SetMaximum(7.5)  
hgdzval.SetMinimum(2.5)  
hgdzval.Draw(“zcolpcol”);

the pcol option of TGraph2D would be very useful if this behavior were fixed,

thanks, Aaron

---

<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:** [February 9, 2012, 8:39am UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/8 "2012-02-09T08:39:57Z")

</div>

I’ll 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:** [February 10, 2012, 9:59am UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/9 "2012-02-10T09:59:33Z")

</div>

This is now fixed in the svn trunk.

---

<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, 8:05pm UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/10 "2018-06-14T20:05:35Z")

</div>

I had the same problem as roodman when using 6.06/09, but when I change the minimum or maximum, the points do not match the correct color in the z-axis. How do I get this fix?

---

<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:** [June 15, 2018, 7:59am UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/11 "2018-06-15T07:59:01Z")

</div>

> [@IzaakWN](#):
>
> when using 6.06/09,

I would suggest you try with a more recent ROOT version. Do you have a small macro reproducing the problem ? .

Please in the future do not use old posts to ask question. This one was finished since 6 years …

---

<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 15, 2018, 11:32am UTC](https://root-forum.cern.ch/t/problems-with-tgraph2d-and-pcol-and-zcol/12595/12 "2018-06-15T11:32:28Z")

</div>

Hi @couet, thanks for the reply. The problem I had was exactly the one from here:

> [@TGraph2D: logarithmic z-axis](https://root-forum.cern.ch/t/tgraph2d-logarithmic-z-axis/16525/19):
>
> Now fixed in master: { 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.0…

I managed to switch to root 6.12/07, and I managed to get it working as expected.
