Changing only the displayed labels

Dear experts,

I do not consider myself a newbie in ROOT but I somehow cannot crack the following, although I believe there’s an easy solutions to it.

I need to change the axis labels, but ONLY those that are displayed at the main division ticks(bin) and also I need to use the original value of the label at each main tick and derive the new one from it. The best way would be to loop over an array of labels. If I had the array I would then use the ChangeLabel(…) method where the new label is derived from the old one.

The problem is that invoking:
histo -> GetXaxis() -> GetLabels()
returns a nullptr all the time

A workaround would be using non-optimised axis divisions and do the changes then. This is however a bit inconvenient due to different axis ranges I need to process.

With kind regards
Karel Cerny

ROOT Version: 6.14/06
Platform: x86_64 Ubuntu 18.04 LTS

GetLabels returns nullptr because your labels are numeric. It returns the list of labels for the alphanumeric user defined labels.There is no direct way to get the value of a numeric label…So you will need to use the same algorithm used by TGaxis. ie:

void AxisLabels(float x1 = 0.214, float x2=2.6, int ndiv=10)

   int    ndivo = 0;
   double x1o   = 0.;
   double x2o   = 0.;
   double bw    = 0.;


   printf ("x1 = %g x1o = %g\n",x1,x1o);
   printf ("x2 = %g x2o = %g\n",x2,x2o);

   double lab = x1o;

   for (int i = 0; i<=ndivo; i++) {
      printf("label number %d is %g\n",i+1,lab);
      lab = lab+bw;

wich gives:

root [0] .x AxisLabels.C
x1 = 0.214 x1o = 0.5
x2 = 2.6 x2o = 2.5
label number 1 is 0.5
label number 2 is 1
label number 3 is 1.5
label number 4 is 2
label number 5 is 2.5
root [1] 

1 Like

Dear Olivier,

thank you!

Cheers, Karel

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