Axis Label Placement

Continuing the discussion from Making sure axis label and title don't overlap:

Ive had a user complain to me about the fact that some of the axis titles are now placed off the screen since version 6.10. This occurs when you have large numbers on the Y-axis, but was not evident in version 6.08 (although here you would have occasional overlap, but you could at least see the label.) Any suggestions on how to fine tune this algorithm, or automatically adjust the axis labels, or the size of the frame?

Here is an example:


{
   TGraph *g = new TGraph();
   g->SetPoint(0,10,15);
   g->SetPoint(1,45000,-25000);
   g->SetTitle(Form("ROOT %s; X-axis; Y-axis", gROOT->GetVersion()));
   g->Draw("AL");
}
1 Like

There is now an automatic placement of the Y axis title when the title offset is 0 (now the default)
The maximale length of the Y labels is looked and the Y axis title is placed accordingly.
I can image that in some case like the one this optimization is not optimale. Setting the Y axis title offset to a non 0 value will cure this.

This means I will have to write a different algorithm to determine the placement of the labels as the current one doesn’t work in all cases. Can you point me to where the current automatic placement algorithm is so I have a starting point? Could we simply change the current algorithm such that the offset is not so large that it is placed off the pad? Something along the lines of this in pseudo code?

if (offest > pad_edge) offset = pad_edge;

No you just need to specify you own position the same as the old defaults and you will be back to the old way … if the old way was ok for you.

Sometimes placing the offset off the pad is used to ease the title …

Ahh ok, you can switch the algorithms (the old behavior was just a default value). I didn’t understand that at first. The documentation doesn’t make this clear as it hasn’t changed between versions. It even states that the default is 1:

I assume previously the behavior was simply to set the offset to 1. This would the reproduce the old behavior:

{
   TGraph *g = new TGraph();
   g->SetPoint(0,10,15);
   g->SetPoint(1,45000,-25000);
   g->SetTitle(Form("ROOT %s; X-axis; Y-axis", gROOT->GetVersion()));
   g->GetYaxis()->SetTitleOffset(1);
   g->Draw("AL");
}

I still think that placing the label off the pad isn’t a great idea as default behavior (even if it is only for some cases). Also, is this behavior different for X-axis and Y-axis?

Yes you are right there is some documentation update to do. I will let you know when done.

I have updated the doc.

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