Axis labels overlapped by pad

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 ?