# Y axis range problems with Draw("same") and Draw("goff")

Hi everybody,

in my PyROOT script, I have a function to compute a median for each x-bin of a 2d histogram and fill the result into its own histogram. The 2d histograms are the result of a i[/i] t.Draw().

Now I would like to superimpose several of these “median curves”. For each, I

• t.Draw() with option “goff”

• i[/i] hist2d = GetHistogram(), store the result

• convert the histogram to my median curve i[/i] hist_medians = medians(hist2d)

• and hist_medians.Draw(“same”)

The problem:

The second t.Draw() uses the y axis range as defined by the first hist_medians.Draw(). Because the range of this curve is rather limited, the second t.Draw() can have many entries in the y-underflow or overflow bins. Depending on how many entries then lie in these y-under-/overflow bins, this means that the second hist_medians.Draw() can be very wrong! (In the extreme case simply clipping the curve at the edge of the window, i.e. the range associated with the first curve.)

How do I fix this?

All the best,
Chris

is hist_medians only a pointer to hist2d or is it a copy of hist2d ?

No, it’s its own object. The “2d-to-1d converter” looks like this:

```def convert_2d(hist,function): # To get X-axis range & labels, start out with ProjectionX hm=hist.ProjectionX() # For each X bin in the original hist for i in range(1,hist.GetNbinsX()+1): # Project to Y within that X bin, store in histogram hpy with appropriate title hpy=hist.ProjectionY(hist.GetTitle()+"_py%d"%i,i,i) # Calculate the median from this temporary hpy median=function(hpy) # Set the median as the value for the corresponding X bin in the curve histogram hm.SetBinContent(i,median) # Return this histogram return hm```

And I have a dictionary where I store

Short update:

I started

• explicitly creating new histograms TH2D(“name”,“title”,nbinsx,…)
• and using Draw("…>>name")