1D Histogram with text axis labels of different colors

Hi - I’m using ROOT 4.00/08.

I’m trying to figure out how to draw a TH1F with an X axis that has text labels, each bin having a different color. Take a histogram with 4 bins from 0 to 4, for example.

I created a transparent TGAxis:

TGaxis *axis = new TGaxis(0,0,4,0,0,4,4,“BM”)

But the problem is that I can’t figure out how to set a bin label for a TGaxis, as you can do for a TAxis, for example: SetBinLabel(2,“B1”).

Thanks for any help.


The alaphanumeric labels are stored at the TAxis level. So you should create a TAxis and set the label as you wish. But TAxis is not able to draw itself. For effeciency reasons all the drawing part of an axis has been delegated to TGaxis. You should also create a TGaxis (as you do now). To make the link between TAxis and TGaxis you should use the TGaxis method TGaxis::ImportAxisAttributes. So you should do something like:

TAxis *a = new TAxis(...) ;
TGaxis *ga = new TGaxis(...);