Strange behaviour (bug?) with TGaxis

Firstly I must appologize for what will probably be a bit of a vague question - I have only limited information at the moment.

Below is a screenshot of some output from my analysis code.

On the bottom figure you can see that I have placed a TGaxis. It is in an unusual location, however this is because I placed it so.

Of more importance is the offset of the labels. The labels intersec the axis ticks. I do not understand why this is the case, and I have not set this behaviour (to my knowledge) in my code. Hence I believe it may be a bug.

I am asking this question for another reason - I recently experienced some crashing of my drawing code. I managed to isolate the issue to be related to the plotting of this axis. At the moment I don’t know anything more than this.

It could possibly be related to this issue, but I do not know for sure.

I don’t expect this to be terribly useful, however this is the code related to the drawing of that axis.

image

image

Here’s what I’ve learned so far… The issue goes away if I remove the “0.0001”.

I put this in here because I read somewhere in the documentation that the x values should not be exactly equal but perhaps I misunderstood for which direction of axis that should be.

image

I need a piece of code reproducing the issue (not screen shots please).

Try this

#include <TCanvas.h>
#include <TGaxis.h>


int main()
{

    TCanvas *c = new TCanvas("canvas", "canvas");
    
    TH1D *h = new TH1D("h", "h", 50, 0.0, 5.0);
    h->SetMinimum(0.0);
    h->SetMaximum(5.0);
    h->Draw();

    TGaxis *axis = new TGaxis(1.0, 0.5, 1.0 + 0.0001, 4.5, 0.5, 4.5, 503, "");
    TGaxis *axis2 = new TGaxis(2.0, 0.5, 2.0 - 0.0001, 4.5, 0.5, 4.5, 503, "");
    axis->Draw();
    axis2->Draw();

    c->Show();

    return 0;

}

Yes you axis you be vertical … other wise it is more tricky to setup.

void birdsall() {
   TCanvas *c = new TCanvas("canvas", "canvas");
   c->DrawFrame(0,0,5,5);

   TGaxis *axis = new TGaxis(1.0, 0.5, 1.0 + 0.0001, 4.5, 0.5, 4.5, 503, "+L");
   TGaxis *axis2 = new TGaxis(2.0, 0.5, 2.0, 4.5, 0.5, 4.5, 503, "+L");
   axis->SetLabelOffset(0.01);
   axis2->SetLabelOffset(0.01);

   axis->Draw();
   axis2->Draw();

   TGaxis *axis7 = new TGaxis(4,0.5,4,4.5, 0,9000,503,"+L");
   axis7->SetName("axis7");
   axis7->SetLabelOffset(0.01);
   axis7->Draw();
}

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