# How to plot z axis for a third variable in root

**URL:** <https://root-forum.cern.ch/t/how-to-plot-z-axis-for-a-third-variable-in-root/57402>\
**Category:** Newbie\
**Created:** [December 5, 2023, 2:38pm UTC](https://root-forum.cern.ch/t/how-to-plot-z-axis-for-a-third-variable-in-root/57402 "2023-12-05T14:38:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![github-arpita](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/github-arpita/32/29476_2.png) [@github-arpita](https://root-forum.cern.ch/u/github-arpita)\
**Post date:** [December 5, 2023, 2:38pm UTC](https://root-forum.cern.ch/t/how-to-plot-z-axis-for-a-third-variable-in-root/57402/1 "2023-12-05T14:38:44Z")

</div>

\_  
  ![plot](https://root-forum.cern.ch/uploads/default/original/3X/9/4/94cdbe8c04bcade350ff4ddbd4f3523452d3f75e.png)  
   
Dear team,  
I want a plot where two variables are plotted on the X and Y axis whereas the third variable can be plotted on the Z axis. An example plot is attached here. Can I get a graph like this?

Thanks and regards,  
Arpita Mondal

---

<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:** [December 5, 2023, 2:45pm UTC](https://root-forum.cern.ch/t/how-to-plot-z-axis-for-a-third-variable-in-root/57402/2 "2023-12-05T14:45:52Z")

</div>

If your data are stored in a 2D histogram `h2` use:

```auto
h2->Draw("colz");

```

If your data are stored in array use [TScatter](https://root.cern/doc/master/classTScatter.html).

---

<div class="post-metadata">

**Author:** ![github-arpita](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/github-arpita/32/29476_2.png) [@github-arpita](https://root-forum.cern.ch/u/github-arpita)\
**Post date:** [December 6, 2023, 5:17am UTC](https://root-forum.cern.ch/t/how-to-plot-z-axis-for-a-third-variable-in-root/57402/3 "2023-12-06T05:17:27Z")

</div>

Thank you for your response.  
My data are stored in an array. So, I am trying to use TScatter. But I got an error like this  
"error: unknown type name ‘TScatter’ "

What should I do?

Thanks and regards,  
Arpita

---

<div class="post-metadata">

**Author:** ![github-arpita](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/github-arpita/32/29476_2.png) [@github-arpita](https://root-forum.cern.ch/u/github-arpita)\
**Post date:** [December 6, 2023, 6:24am UTC](https://root-forum.cern.ch/t/how-to-plot-z-axis-for-a-third-variable-in-root/57402/4 "2023-12-06T06:24:29Z")

</div>

We can use TScatter for version 6.30. But I have Root version-6.22.  
Is there any easy way to update my Root version from 6.22 to 6.30?  
I need to complete the plot. So if you can help me it will be great.

Thanks and regards,  
Arpita

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [December 6, 2023, 9:05am UTC](https://root-forum.cern.ch/t/how-to-plot-z-axis-for-a-third-variable-in-root/57402/5 "2023-12-06T09:05:21Z")

</div>

Yes: [Installing ROOT - ROOT](https://root.cern/install/)

---

<div class="post-metadata">

**Author:** ![github-arpita](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/github-arpita/32/29476_2.png) [@github-arpita](https://root-forum.cern.ch/u/github-arpita)\
**Post date:** [December 6, 2023, 11:52am UTC](https://root-forum.cern.ch/t/how-to-plot-z-axis-for-a-third-variable-in-root/57402/6 "2023-12-06T11:52:18Z")

</div>

Thanks for the help. I have installed root\_v6.30.02 and I have got the desired plot.
