Axis labels overlapped by pad

You can change the axis label offset (TAttAxis::SetLabelOffset). This function
is also available interactively with the graphics editor.

Rene

Dear Rene,

The problem with the labels is not their horizontal positioning (which the axis label offset controls) but their vertical positioning. The lowest Y axis label on the top graph can be cut in half by the bottom pad, and likewise the highest Y axis label on the lower graph can be cut in half by the top pad.

The solutions proposed so far have been

a) to enlarge the lowest pad up a bit to clip the number entirely
- This leads to clipping of data, too
i) SetMinimum() on the graph so that the data moves up
- The axis label moves up too, negating enlarging the lowest pad

b) to occlude the number manually by drawing on top of it.

  • This is nasty. The original problem is not always a problem, sometimes the axis label is drawn a bit upwards, in which case manually drawing on top of it will cause the original problem again. So now it is necessary to manually choose for each plot whether they need to be manually clipped or not. When you have many plots, and the problem can happen on the upper or the lower plot, this gets to be a pain.

Regards,

  • Peter

Let me make one more follow-up to the latest comment. The issue is the
bottom alignment in vertical direction for y-axis and left-alignement in horizontal axis. I have a set of base-macros use to generate plots with multiple sub window (n= nxny) . Attached are two examples for a 21 divisions having same y-axis for both (no content only frames positioned on pads) one has the pads completely aligned, and here you loose 'half the 0
for the second label axis. If this ‘o’ text (and the 0.5 1 etc were left aligned they would all be within the pad for that frame (both one and two has a bottom margin to accommodate the axis title). The second display show you can regain good visual effects by introducing a small margin for the second plot.
This surely look good with current root, but sometime it is nice to really have the two plots/pads together indicating they share the same y-axis in this case.

I hope this helps communicating the message that I believe peter is trying to get across.

best regards
Flemming




I’ve been using the technique of drawing a TPad over the offending number, but even this is unsatisfactory without rather a lot of tweaking. In some of the EPS outputs, the TPad overlaps the axis too, creating a gap in the axis itself! yuck. :confused:

  • Peter

Did anybody find a solution for this problem?
Aligning the label upon the tick mark of the y-axis would be probably the most easy and straightforward solution: is there any way to do that?

Maurizio

Several “problems” have been listed in this post. Which one are you referring to ? can you send me a small example macro ? I will look at it.

I want to align the y-axis labels upon the tick marks to avoid the “half 0” label, highlighted by the arrow in the picture.

Maurizio


testPlotRes.c (1.22 KB)

Yes that’s a tricky case. I would recommend to draw a white filled TPad on top of the 0 like in:

   TCanvas *c = new TCanvas("c","c",600,600);
   c->Divide(1,2,0,0);
   TVirtualPad *p;
   p = c->cd(1);
   p->DrawFrame(0.5, 0.,0.9,299.);
   p = c->cd(2);
   p->DrawFrame(0.5, 0.,0.9,299.);
   c->cd();
   b = new TPad("b", "b",0.05201342,0.479021,0.08557047,0.5314685);
   b->SetBorderMode(0);
   b->Draw();

[quote=“couet”]Yes that’s a tricky case. I would recommend to draw a white filled TPad on top of the 0 like in:

TCanvas *c = new TCanvas("c","c",600,600); c->Divide(1,2,0,0); TVirtualPad *p; p = c->cd(1); p->DrawFrame(0.5, 0.,0.9,299.); p = c->cd(2); p->DrawFrame(0.5, 0.,0.9,299.); c->cd(); b = new TPad("b", "b",0.05201342,0.479021,0.08557047,0.5314685); b->SetBorderMode(0); b->Draw(); [/quote]

Running your example doesn’t solve my problem.
Am I wrong?


for me the 0 is erased… (I just tried)…

I’m resurrecting this old post from 2010 because I’m running into the same problem two years later. Is there still no straightforward way to avoid clipping the first bin label in aligned pads?

@Wile E Coyote:

Your link (and its child links) don’t appear to provide an immediate, general solution: it still requires tweaking per plot, which isn’t ideal for such a common style of plot you might want to make.

Why do pads have to be filled with white? If they were transparent and only the axes were drawn then the labels would not be covered. This may still be confusing to the reader if for example the 0 is at the interface of two plots, but at least it is not as disruptive to the eye.

Is there anyway to make transparent pads?

   c1->SetFillColor(0);
   c1->SetFrameFillStyle(0);

Here is a solution for the “overlapped” zero (in fact, it’s rather truncated than overlapped).
The main idea is to give the upper pad enough bottom margin to display the zero properly.
In addition, the lower pad overlaps the upper pad and therefore, should be transparent (SetFrameFillStyle(4000)) (I parameterized this situation in my example).
I didn’t adjust the label size to keep the code easy.

[code]void ratio() {
float r = 0.3;
float epsilon = 0.02;

TH1F *h1 = new TH1F(“h1”, “test1”, 100, -3, 3);
h1->SetStats(0);
h1->GetXaxis()->SetLabelSize(0.);
h1->GetXaxis()->SetTitleSize(0.);
h1->FillRandom(“gaus”, 200000);
h1->SetMinimum(0.);

TH1F *h2 = new TH1F(“h2”, “test2”, 100 , -3, 3);
h2->SetStats(0);
h2->FillRandom(“gaus”, 100000);

TCanvas *c1 = new TCanvas(“c1”, “example”, 600, 700);
TPad *pad1 = new TPad(“pad1”, “pad1”, 0, r-epsilon, 1, 1);
pad1->SetBottomMargin(epsilon);
c1->cd();
pad1->Draw();
pad1->cd();
h1->Draw();

TPad pad2 = new TPad(“pad2”, “pad2”, 0, 0, 1, r(1-epsilon));
pad2->SetTopMargin(0);
pad2->SetFrameFillStyle(4000);
c1->cd();
pad2->Draw();
pad2->cd();
h2->Draw(“ep”);
}
[/code]


[quote=“mrieger”]Here is a solution for the “overlapped” zero (in fact, it’s rather truncated than overlapped).
The main idea is to give the upper pad enough bottom margin to display the zero properly.
In addition, the lower pad overlaps the upper pad and therefore, should be transparent (SetFrameFillStyle(4000)) (I parameterized this situation in my example).
I didn’t adjust the label size to keep the code easy.

[code]void ratio() {
float r = 0.3;
float epsilon = 0.02;

TH1F *h1 = new TH1F(“h1”, “test1”, 100, -3, 3);
h1->SetStats(0);
h1->GetXaxis()->SetLabelSize(0.);
h1->GetXaxis()->SetTitleSize(0.);
h1->FillRandom(“gaus”, 200000);
h1->SetMinimum(0.);

TH1F *h2 = new TH1F(“h2”, “test2”, 100 , -3, 3);
h2->SetStats(0);
h2->FillRandom(“gaus”, 100000);

TCanvas *c1 = new TCanvas(“c1”, “example”, 600, 700);
TPad *pad1 = new TPad(“pad1”, “pad1”, 0, r-epsilon, 1, 1);
pad1->SetBottomMargin(epsilon);
c1->cd();
pad1->Draw();
pad1->cd();
h1->Draw();

TPad pad2 = new TPad(“pad2”, “pad2”, 0, 0, 1, r(1-epsilon));
pad2->SetTopMargin(0);
pad2->SetFrameFillStyle(4000);
c1->cd();
pad2->Draw();
pad2->cd();
h2->Draw(“ep”);
}
[/code][/quote]

Your solution is not working when saving pdf

this one is ok

void ratio() {
  float r = 0.3;
  float epsilon = 0.02;

  TH1F *h1 = new TH1F("h1", "test1", 100, -3, 3);
  h1->SetStats(0);
  h1->GetXaxis()->SetLabelSize(0.);
  h1->GetXaxis()->SetTitleSize(0.);
  h1->FillRandom("gaus", 200000);
  h1->SetMinimum(0.);

  TH1F *h2 = new TH1F("h2", "test2", 100 , -3, 3);
  h2->SetStats(0);
  h2->FillRandom("gaus", 100000);

  TCanvas *c1 = new TCanvas("c1", "example", 600, 700);
  TPad *pad1 = new TPad("pad1", "pad1", 0, r-epsilon, 1, 1);
  pad1->SetBottomMargin(epsilon);
  c1->cd();
  pad1->Draw();
  pad1->cd();
  h1->Draw();

  TPad *pad2 = new TPad("pad2", "pad2", 0, 0, 1, r*(1-epsilon));
  pad2->SetTopMargin(0);
  pad2->SetFillColor(0);
  pad2->SetFillStyle(0);
  c1->cd();
  pad2->Draw();
  pad2->cd();
  h2->Draw("ep");
}

Hi,

this solution seems to work when the plot is saved in PNG format, but the “0” is still cropped when the same canvas is saved in PDF or EPS format!

Not for me on MAcOsx using ROOT 6.04. On which machine are you running ? with which root version ? do you run in batch ?