How to set labels in each bin with the number of events

Dear root experts,

I have make a TGraphErrors with the information of an Histogram. Now I want to plot the number of events inside each bin on the plot, something that looks like this:

Anyone could explain me how to make it?

Many thanks, Nahual

Well, you would need to loop over the points in the TGraphErrors and get the X and Y coordinates. Probably the GetPoint method is best for that.

Then for each point, draw a TText at the point’s coordinates (maybe shifted a bit down) with the text label being the number you want.

You’ll probably have to play around a bit with the text size, position shifting, etc, before you can get it to look like your example.


For histograms you can use the TEXT option: