In case of logaritmic x-axis root paints histogram outside the frame, see the following code.
TH1::SetDefaultSumw2(true);
TH1D *h1, *h2;
h1 = new TH1D("h1", "", 20, 1, 30);
h2 = new TH1D("h2", "", 20, 1, 30);
for(int i = 0; i < 100000; ++i) {
h1->Fill( 30*pow(gRandom->Gaus(),2) );
h2->Fill( 40*pow(gRandom->Gaus(),2) );
}
TCanvas *can = new TCanvas("can");
can->SetLeftMargin(0.4);
h1->Draw();
h1->SetMaximum(6000);
h2->SetLineColor(kRed);
h2->SetLineWidth(3);
h2->Draw("same");
gPad->SetLogx();
h1->GetXaxis()->SetRangeUser(8.4, 30);
couet
May 16, 2017, 7:42am
3
A workaround is to apply the same range on h2:
{
TH1::SetDefaultSumw2(true);
TH1D *h1, *h2;
h1 = new TH1D("h1", "", 20, 1, 30);
h2 = new TH1D("h2", "", 20, 1, 30);
for(int i = 0; i < 100000; ++i) {
h1->Fill( 30*pow(gRandom->Gaus(),2) );
h2->Fill( 40*pow(gRandom->Gaus(),2) );
}
TCanvas *can = new TCanvas("can");
can->SetLeftMargin(0.4);
h1->SetMaximum(6000);
h1->Draw();
h1->GetXaxis()->SetRangeUser(8.4, 30);
gPad->SetLogx();
h2->SetLineColor(kRed);
h2->SetLineWidth(3);
h2->Draw("same");
h2->GetXaxis()->SetRangeUser(8.4, 30);
}
Thanks,
It’s quite confusing to call SetRangeUser for every object drawn with “same” to prevent painting outside, but why not, it’s working.
I am just wondering why the same script with linear-axis works well, whereas log-axis has this peculiar feature. It is probably not by purpose.
Cheers
Radek
couet
May 23, 2017, 9:07am
5
I agree with you this is not the right behavior. I will have a look if something can be done.
system
Closed
June 6, 2017, 9:07am
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.