Histogram with text bar same option

Yes, I understand that it is more complicated, especially that it would have to be extended to many histograms. The sample code that did this plot I attached in previous posts.

Fortunately it’s a one time task for me and I’ll stick with my code, but surely it would be a nice addition to ROOT, since at least a few other plotting packages must support this feature - plots in papers with such shifted labels and connecting lines are not uncommon :slight_smile:

The algorithm has to be define…
Not clear on your pict what are the rules to draw the line or not.
but yes … why not …

These rules should depend on font size, etc. My code is not universal. I think it could be summarized as:

  1. Calculate the bar width w1 below which it is possible that labels may overlap, and a minimal vertical distance that should separate such overlapping labels: D
  2. Check the distance of each label to it’s two neighbouring labels: d1, d2
  3. If d1<D and d2<D move the label D pixels above position of the highest of the neighbouring labels
  4. if d1D, check if the label moved D above the ovrlapping neghbouring label will not overlap with the second label. If not, just move it. If yes, move it above both labels, as in step (3).
  5. Draw the lines from the head of the bar to the bottom of the label for each of moved labels.

I guess this algorithm should be the same no matter what the number of histograms is. The question is how to calculate D, w1, etc, depending on the font size, bar width, etc.