# Surprising behaviour of TH2 when using automatic binning

**URL:** <https://root-forum.cern.ch/t/surprising-behaviour-of-th2-when-using-automatic-binning/57908>\
**Category:** ROOT\
**Tags:** graphics, hist\
**Created:** [January 19, 2024, 2:58pm UTC](https://root-forum.cern.ch/t/surprising-behaviour-of-th2-when-using-automatic-binning/57908 "2024-01-19T14:58:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![olantwin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@olantwin](https://root-forum.cern.ch/u/olantwin)\
**Post date:** [January 19, 2024, 2:58pm UTC](https://root-forum.cern.ch/t/surprising-behaviour-of-th2-when-using-automatic-binning/57908/1 "2024-01-19T14:58:12Z")

</div>

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](https://root.cern.ch/doc/master/classTH1.html#auto-bin), I haven’t found documentation for TH2).

Example:

```python
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.

Example:

```python
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

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [January 20, 2024, 4:03pm UTC](https://root-forum.cern.ch/t/surprising-behaviour-of-th2-when-using-automatic-binning/57908/2 "2024-01-20T16:03:30Z")

</div>

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?

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [January 22, 2024, 10:09am UTC](https://root-forum.cern.ch/t/surprising-behaviour-of-th2-when-using-automatic-binning/57908/3 "2024-01-22T10:09:57Z")

</div>

Hello,

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, [https://its.cern.ch/jira/browse/ROOT-7714/](https://its.cern.ch/jira/browse/ROOT-7714/)  
Thank you for reporting this. I hope this can be implemented soon, or if not a Warning message would be produced.

Lorenzo

---

<div class="post-metadata">

**Author:** ![olantwin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@olantwin](https://root-forum.cern.ch/u/olantwin)\
**Post date:** [January 22, 2024, 10:54am UTC](https://root-forum.cern.ch/t/surprising-behaviour-of-th2-when-using-automatic-binning/57908/4 "2024-01-22T10:54:42Z")

</div>

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](https://root-forum.cern.ch/t/automatic-axis-range-for-2d-and-3d-histograms/19962), linked in the issue, might be of interest.

All the best,  
Oliver

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [February 5, 2024, 10:55am UTC](https://root-forum.cern.ch/t/surprising-behaviour-of-th2-when-using-automatic-binning/57908/5 "2024-02-05T10:55:39Z")

</div>

Closed on February 5, 2024, 10:55am UTC

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