Surprising behaviour of TH2 when using automatic binning

When using RDataFrame::Histo2D, passing a TH2DModel with identical lower/upper limits, the histogram range is automatically determined (I guess it’s a case of this: ROOT: TH1 Class Reference, I haven’t found documentation for TH2).


hxy = df.Histo2D(("xy", "xy; x; y", 100, -1,-1, 100, -1, -1), "x", "y")

Normally this seems to work fairly well but I’m looking at a few cases right now, where I have over/underflows in one or both of the axes.

Two questions:

  1. Is this a bug or could this be an issue with insufficient buffer size (as mentioned in the TH1 documentation)? If this is the case, is there a way to control the buffer size for Histo2D, when the underlying TH2 is not directly handles by the user?

  2. When automatically binning one axis, explicitly-given ranges for the other axis are silently ignored. Maybe Histo2D/TH2 could warn about this behaviour, if this is the intended behaviour/due to inherent limitations.


hxy = df.Histo2D(("xy", "xy; x; y", 100, -1,-1, 100, 0, 10), "x", "y")
# Expect: automatic bins for x, given bins for y. Result: automatic bins for both

ROOT version: 6.30.02

Dear @olantwin ,

This seems more like a behaviour of TH2 proper rather than Histo2D. I believe @couet will know more about your questions. In any case, would you be able to share reproducers of your issues so we can further debug?



  1. The default buffer size for the histogram is 1000 entries. You can increase it by calling the static function, before using the histograms, TH1::SetDefaultBufferSize(...)

  2. There is no support for one axis with automatic binning and one normal pre-defined binned axis. We have already a new issue opened for this,
    Thank you for reporting this. I hope this can be implemented soon, or if not a Warning message would be produced.


Thanks a lot, Lorenzo, for the clear explanation! All my questions are answered.

I’ll keep an eye on the issue.

For other readers, this thread, linked in the issue, might be of interest.

All the best,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.