SetMoreLogLabels + ChangeLabel not working

Dear ROOTers,

I am trying to change the labels of a logged axis after having set more labels to it, i.e.

h.GetXaxis().SetMoreLogLabels()
h_ratio.GetXaxis().ChangeLabel(-1,-1,-1,-1,kRed,-1,"Changed")
h_ratio.GetXaxis().ChangeLabel(-2,-1,-1,-1,kBlue,-1,"Changed")
h_ratio.GetXaxis().ChangeLabel(1,-1,-1,-1,kGreen,-1,"Changed")
pad2.SetLogx()

where I am based on ChangeLabel method does not work properly - #2 by couet. However, the labNum value of the ChangeLabel method relates to the one prior to .SetMoreLogLabels() implementation.

Let me clarify: using same code block as above without pad2.SetLogx() yields:

however when including pad2.SetLogx() one gets:

which means the labels I set out to change are outside of the plot region. Is there any way to overcome this?

Many thanks in advance!


_ROOT Version: 6.22/06
_Platform: linuxx8664
_Compiler: gcc


Thanks for your report. Can you post a small reproducer ?

Sure @couet and thanks for your reply.

c = TCanvas("c", "canvas", 800, 800)
h = TH1D("h","Gauss",6,-3,3)

for i in range(1000):
  x = gRandom.Gaus(0,1.5)
  w = 2*gRandom.Rndm()
  h.Fill(x,w)

h.Fit("gaus")
h.GetXaxis().ChangeLabel(1,-1,-1,-1,-1,-1,"#pi")
h.GetXaxis().ChangeLabel(2,-1,-1,-1,-1,-1,"#pi")
h.Draw()

yields this (as expected):

However, when one does

c.SetLogx()
h.SetMoreLogLabels()
h.GetXaxis().ChangeLabel(3,-1,-1,-1,-1,-1,"#pi")
h.Draw()

one gets

which means that the number of the label that was changed (in this case, label number 3) relates to the state of the histogram before applying h.SetMoreLogLabels(). My objective, in the context of this reproducer, would be to control a label added by h.SetMoreLogLabels() e.g. the 2X10^-1 label.

Hope this is clearer now.

I have this small reproducer now:

{
   auto c = new TCanvas();
   c->SetLogx();
   auto h = new TH1F("h","h",100,1.,10);
   TAxis* a = h->GetXaxis();
   a->SetMoreLogLabels();
   a->ChangeLabel(1,-1,-1,-1,-1,-1,"#1 Changed");
   a->ChangeLabel(1,-1,-1,-1,-1,-1,"#3 Changed");
   h->Draw();
}

Label #1 is changed but not label #3.

Thanks for your response @couet but this merely proves the problem:
if you added this line:
a.ChangeLabel(2,-1,-1,-1,-1,-1,"#2 Changed")
the result is:
image

i.e. instead of changing the label marked “2” this changed the label marked “10”, which is not what I want…

Exactly. I just posted this small macro to keep track of the script I am using to debug this bug. I am working on it and hope to come soon with a fix.

Ah ok, great, thanks! Counting on your endless resourcefulness as always @couet :slight_smile:

1 Like

This PR fixes the problem: Implement ChangeLabel with SetMoreLogLabels by couet · Pull Request #9400 · root-project/root · GitHub
Thanks to have reported this problem.

{
   auto c = new TCanvas();
   c->SetLogx();
   auto h = new TH1F("h","h",100,1.,10);
   TAxis* a = h->GetXaxis();
   a->SetMoreLogLabels();
   a->ChangeLabel(1,-1,-1,-1,-1,-1,"#1 Changed");
   a->ChangeLabel(3,-1,-1,-1,-1,-1,"#3 Changed");
   a->ChangeLabel(10,-1,-1,-1,kRed,-1,"");
   h->Draw();
}

Thank you @couet! Sorry for my ignorance, but does it mean that in order to be implemented on my machine I would need to reinstall ROOT?

First the PR need to be merged to master (tests are in progress), once done the fix will be in master sources, and yes to have it on your machine immediately you will need to re-install ROOT.

I understand, many thanks!

PR is merged

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