Accessing labels of secondary tick marks

Hello everyone,

I am having trouble accessing the labels of secondary tick marks in a log axis. In practice, I would like to keep the primary tick mark labels, and some of the secondary ones. I provide an example below:

    TH1D *h = new TH1D("h", "some histogram", 5, 0, 2.1);
    for (int i=0; i<5; i++) {
        for (int j=0; j<=i; j++) h->Fill(i*0.42);
    }
    h->GetXaxis()->SetTitle("ln(0.4/x)");

    TCanvas *c = new TCanvas("c", "second axis", 800, 600);
    h->Draw();

    c->SetBottomMargin(0.3);

    auto axis = new TGaxis(2.1, 0.02, 0. ,0.02, 0.048982571, 0.4, 2,"NIGS-");
    axis->SetTitle("x");
    axis->CenterTitle();
    axis->SetTitleFont(43);
    axis->SetTitleSize(20);
    axis->SetTitleOffset(1.2);
    axis->SetLabelFont(43);
    axis->SetLabelSize(20);
    axis->SetLabelOffset(0.05);
    axis->SetTickSize(0.02);
    axis->SetMoreLogLabels(); // add the secondary tick labels
    // axis->ChangeLabel(1,-1,-1,-1,-1,-1,"-#pi");
    axis->ChangeLabel(510,-1,-1,-1,-1,-1,"this");
    axis->SetNoExponent();
    axis->Draw();

So the second axis is a log axis, where I want to keep from the secondary tick labels the 0.4, 0.3, 0.2 and 0.05, and get rid of the ones between 0.05 and 0.1, but with ChangeLabel() so far I have only managed to access the primary tick mark 0.1.

I am using ROOT 6.14 and can easily access up to 6.28.

Thanks in advance,
Lida

ROOT Version: 6.14
Platform: Centos 7

Hi Lida,

You can try to “erase” axis labels providing labSize argument 0:

    axis->ChangeLabel(1,-1,0);
    axis->ChangeLabel(2,-1,0);

Here 1 and 2 are labels indexes. See more info in documentation

In newer ROOT versions you also can modify axis labels by its values:

    axis->ChangeLabelByValue(0.05,-1,0);
    axis->ChangeLabelByValue(0.06,-1,0);

Regards,
Sergey

Dear Sergey,

Thanks for your response.

Unfortunately, ChangeLabel() has only worked for the primary tick marks in version 6.14. Meaning ChangeLabel(1,-1,0) affects the 0.1 label in the example above. I tried accessing the secondary labels with labNum=100 following the ndiv numbering scheme but it didn’t work.

I ended up installing version 6.30 on my own machine and I see that ChangeLabel(1, -1, 0) in this version actually affects the rightmost label (0.05) instead. Odd change from version to version.

I would really like to replicate this behavior in version 6.14 if possible, as it is the version on the machine at my institute.

Cheers,
Lida

Hi,

Version 6.14 is really old and most probably has bugs - which were fixed afterwards.

The only I can recommend - try experimentally which labNum value suppress labels.

Regards,
Sergey

Hi Sergey,

Thanks for your help. I will probably end up doing the cosmetic changes on a newer version.

Best,
Lida