Horizontal offset of x axis labels

Hey there,

I have a histogram with an axis with rotated labels. The labels don’t quite align with the axis though, it looks like their center point is right above the corresponding tick, but it should be their ends that are aligned.

In this picture, the labels are actually set to correspond to a main tick. They are misaligned, aren’t they?

I was looking at the class reference of TAxis, but I only found ways to set the Y offset for both the axis title and the labels. Can I somehow add a Y offset too?

can you provide am example producing this effect ?

In pyROOT:

canvas = ROOT.TCanvas("FpixBpixCanvas")
graph = ROOT.TGraph(1)
canvas.SetBottomMargin(0.3)
graph.Draw("0AP")
graph.GetXaxis().SetNdivisions(-525)
graph.GetXaxis().SetLabelOffset(0.1)
for numBin in range(26):
    graph.GetXaxis().ChangeLabel(numBin + 1, 60, 0.018, -1, -1, -1, "ALongLabelMakesItObvious" + str(numBin))

{
   auto *canvas = new TCanvas("FpixBpixCanvas");
   auto *graph = new TGraph(1);
   canvas->SetBottomMargin(0.3);
   graph->Draw("0AP");
   graph->GetXaxis()->SetNdivisions(-525);
   graph->GetXaxis()->SetLabelOffset(0.005);
   graph->GetXaxis()->CenterTitle();
   graph->GetXaxis()->SetTitleOffset(3.1);

   for (int numBin=1;  numBin <= 26; numBin++)
      graph->GetXaxis()->ChangeLabel(numBin, 60, 0.02, 31, -1, -1,
                                     Form("ALongLabelMakesItObvious %d", numBin));
}

1 Like

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