# Projection onto Y axis

**URL:** <https://root-forum.cern.ch/t/projection-onto-y-axis/51787>\
**Category:** Newbie\
**Created:** [October 2, 2022, 4:42am UTC](https://root-forum.cern.ch/t/projection-onto-y-axis/51787 "2022-10-02T04:42:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex14](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@alex14](https://root-forum.cern.ch/u/alex14)\
**Post date:** [October 2, 2022, 4:42am UTC](https://root-forum.cern.ch/t/projection-onto-y-axis/51787/1 "2022-10-02T04:42:02Z")

</div>

Hi, I’m new to root, and I have a question regarding the 2D histogram - projection to the Y axis. I’ve opened a file and extracted the TH2D histogram that I want, projected and drew it onto the X axis as a TH1D histogram. What I want to do is to specify a range on the X axis, for example, from 53.5 to 66, and make a projection of that range onto the Y axis.  
I’ve tried several example codes, but nothing seems to work. I was wondering can someone please give me some advice on how to do this. Thank you. 🙂

---

<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:** [October 2, 2022, 6:30am UTC](https://root-forum.cern.ch/t/projection-onto-y-axis/51787/2 "2022-10-02T06:30:23Z")

</div>

```cpp
Double_t firstx = 53.5, lastx = 66.0;
Int_t firstxbin = h2d->GetXaxis()->FindFixBin(firstx);
Int_t lastxbin = h2d->GetXaxis()->FindFixBin(lastx);
TH1D *hpy = h2d->ProjectionY("_py", firstxbin, lastxbin, "");

```

---

<div class="post-metadata">

**Author:** ![alex14](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@alex14](https://root-forum.cern.ch/u/alex14)\
**Post date:** [October 2, 2022, 5:35pm UTC](https://root-forum.cern.ch/t/projection-onto-y-axis/51787/3 "2022-10-02T17:35:24Z")

</div>

Thank you so much.
