# How to plot the X and Y axis projection on a 3D plot

**URL:** <https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309>\
**Category:** Newbie\
**Tags:** tree, hist, root\
**Created:** [March 31, 2023, 1:54pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309 "2023-03-31T13:54:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [March 31, 2023, 1:54pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/1 "2023-03-31T13:54:55Z")

</div>

Hi,

I am plotting a 3D plot (mass-energy spectrum with 2D fitting):

 ![3d](https://root-forum.cern.ch/uploads/default/original/3X/a/a/aa17d82bbb1558fb97eaa12826d9a6d9a195b8fb.jpeg)

In the plot I would like to plot the projection of the TKE axis as well as the mass axis to show the 1D spectrum (in the white space opposite to the corresponding axis ). How to plot the x (Mass) and y (TKE) projections on the 3D plot.

---

<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:** [March 31, 2023, 2:21pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/2 "2023-03-31T14:21:46Z")

</div>

You need to divide your canvas in 4 part and draw the 1D historgam in the pads corresponding to the X and Y projections.

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [March 31, 2023, 2:24pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/3 "2023-03-31T14:24:08Z")

</div>

Are there any examples available, as of now I won’t see how to do this…

---

<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:** [March 31, 2023, 2:27pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/4 "2023-03-31T14:27:01Z")

</div>

[https://root.cern/doc/master/h2proj\_8C.html](https://root.cern/doc/master/h2proj_8C.html)

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [April 3, 2023, 11:22am UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/5 "2023-04-03T11:22:08Z")

</div>

Hi, Thanks for sharing the example.

To show a schematic representation of how I want to plot the x and y projection, please see the image :

 ![Capture](https://root-forum.cern.ch/uploads/default/original/3X/c/e/ce2382770b768f6a32e3239ee63b2aa70af22517.jpeg)

Unfortunately I can’t place my pads, that too tilted on the lego 3D plot, is it possible to do it ?

Here I attach the macro and the 2D histogram I use :

[Hist0new\_158.root](https://root-forum.cern.ch/uploads/short-url/2X3FK6Tgw6CqaOT3hurwop5L2OY.root) (8.3 KB)  
[myver\_h2proj.C](https://root-forum.cern.ch/uploads/short-url/uSOy87ugZgzzAfTLKyC0ip1fm0d.C) (777 Bytes)

thank you !

---

<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:** [April 3, 2023, 12:53pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/6 "2023-04-03T12:53:30Z")

</div>

No, it is not, easily, possible. You can have cut planes with GL but that’s not what yu are looking for.

 ![Screenshot 2023-04-03 at 14.53.05](https://root-forum.cern.ch/uploads/default/original/3X/c/e/ce5d5f47a3b233cbfc6b3b0c343c59e9f063f61e.jpeg)

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [April 3, 2023, 1:08pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/7 "2023-04-03T13:08:36Z")

</div>

No its not what I am looking for. I think it my be possible with pyroot (uisng matplotlib, unfortunately I have never used it…) as shown below :

 ![Capture1](https://root-forum.cern.ch/uploads/default/original/3X/4/e/4e74184279cbb55f2aa49cd677ef3ae0195e5df9.jpeg)

something like this…

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 3, 2023, 1:20pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/8 "2023-04-03T13:20:56Z")

</div>

@gini See your previous post again.  
The 3-D plot has a vertical axis maximum of about 180.  
The “`Mass (ie x axis)`” and “`Energy (ie y axis)`” plots need vertical axis maximums of, respectively, 4000 and 4500 (i.e., they will not fit on the 3-D back-boxes).

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [April 3, 2023, 1:31pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-x-and-y-axis-projection-on-a-3d-plot/54309/9 "2023-04-03T13:31:15Z")

</div>

Yeah thats also a concern, so what I do is I plot my 2D histogram from my mass and tke branch (see plot1) and using TBrowser I plot my lego my 3D histogram (see plot 2) :

![plot1](https://root-forum.cern.ch/uploads/default/original/3X/9/7/9746f92e465c048136c76744eb6f50a12811fb5c.jpeg)

 ![plot2](https://root-forum.cern.ch/uploads/default/original/3X/a/1/a13d12d703d6b9c267568e0c7a50d8438020184e.jpeg)

So if I understand things correctly then I need to normalise the x and Y projections before plotting it on the back boxes of my 3D histogram .
