How are bins filled?

Dear experts,

Taking a close look at 2-d histograms, it seems that the events which fall inside any given bin are made to take up the whole area of the bin, I guess in some random way.

Is there any more detailed information available about this?


I guess what you should search for “scatter” in the THistPainter class description.

In the multi-dimensional histograms, the default draw option draws a number of points in the bins equal to the number of entries. Since the histogram doesn’t store the actual values, it has no way of drawing the points at their pre-binned values, so it draws them randomly distributed inside the bin.

This is the documentation section that talks about it: I guess you’d have to look into the THistPainter source code to find out more details (e.g. how are the random positions selected?)

It’s annoying that the default behaviour is misleading in this way (of drawing random points), because it makes the plot look like a real unbinned scatter plot instead of a binned histogram. Unfortunately none of the other options make good defaults for multi-dimensional histograms either.


To get a scatter plot with the exact points’ positions you should use a TTree or a TNtuple.