# Draw the same histogram, only filtered

**URL:** <https://root-forum.cern.ch/t/draw-the-same-histogram-only-filtered/60459>\
**Category:** Newbie\
**Tags:** python, hist, root\
**Created:** [August 9, 2024, 12:00pm UTC](https://root-forum.cern.ch/t/draw-the-same-histogram-only-filtered/60459 "2024-08-09T12:00:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kirill\_Sm](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kirill_sm/32/35179_2.png) [@Kirill\_Sm](https://root-forum.cern.ch/u/Kirill_Sm)\
**Post date:** [August 9, 2024, 12:00pm UTC](https://root-forum.cern.ch/t/draw-the-same-histogram-only-filtered/60459/1 "2024-08-09T12:00:55Z")

</div>

_ROOT Version:_ 6.26.10  
_Platform:_ Windows

* * *

Hi everyone!

I was wondering if there is a possible way to draw a histogram that you already created, only filtered.

More particularly, I used the ProjectionX function to create a projection of a 2-dimensional histogram:

hist\_projection = hist.ProjectionX(projection\_name, start\_y\_bin, end\_y\_bin)\

Now I am wondering if there is a way to create the projection but only for the results that satisfy some condition “QEL==True”, without “filtering” the result before the projection function.

I’m using PyRoot.

Thank you in advance!  
K

---

<div class="post-metadata">

**Author:** ![silverweed](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/silverweed/32/36670_2.png) [@silverweed](https://root-forum.cern.ch/u/silverweed)\
**Post date:** [August 9, 2024, 12:18pm UTC](https://root-forum.cern.ch/t/draw-the-same-histogram-only-filtered/60459/2 "2024-08-09T12:18:27Z")

</div>

Hello @Kirill_Sm,

I’m not sure if you can filter an already-created histogram (maybe @couet knows more about this).

If you are able to use [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) to produce the histogram, you can achieve what you want very easily by defining a new column and filtering it through your condition. This is a non-destructive operation that preserves the other column and would allow you to plot both the 2d histo (if needed) and the filtered projected version.
