# How do I draw a histogram with a condition?

**URL:** <https://root-forum.cern.ch/t/how-do-i-draw-a-histogram-with-a-condition/61983>\
**Category:** Newbie\
**Tags:** python, hist, root\
**Created:** [October 21, 2024, 11:09am UTC](https://root-forum.cern.ch/t/how-do-i-draw-a-histogram-with-a-condition/61983 "2024-10-21T11:09:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Terklton](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/terklton/32/37678_2.png) [@Terklton](https://root-forum.cern.ch/u/Terklton)\
**Post date:** [October 21, 2024, 11:09am UTC](https://root-forum.cern.ch/t/how-do-i-draw-a-histogram-with-a-condition/61983/1 "2024-10-21T11:09:36Z")

</div>

Hi. I have a simple question in root python.

Let’s say I’m trying to plot a histogram of column X such that column Y==1. Is there a way of doing it inside the definition of the histogram and not to define new columns, etc?

I mean something like this:

h = df.Histo1D(“X”, **“Y==1”** )  
c = ROOT.TCanvas()  
h.Draw()  
c.Draw()

Assume that each event (row) in the dataframe can have multiple entries, such that they can have different Y’s.

Sometimes I want to do a quick check and defining new columns takes too long.

Thank you

_ROOT Version:_ JupyROOT 6.30/04  
_Platform:_ Jupyter

* * *

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [October 21, 2024, 11:46am UTC](https://root-forum.cern.ch/t/how-do-i-draw-a-histogram-with-a-condition/61983/2 "2024-10-21T11:46:55Z")

</div>

Hello,

You cannot filter events directly in the Histogramming Action.  
In RDataFrame, the filtering should happen with `Filter`:

```auto
h = df.Filter('Y==1').Histo1D('X')

```

Cheers,  
D
