X axis range

Dear experts,

I want to plot an histogram in a canvas with 2 pad, but I want to use different x range.
I did the fellowing:

  TCanvas *c = new TCanvas("c", "", 700, 700);
  c->Divide(1,2);
  c->cd(1);
  hrsp->GetXaxis()->SetRangeUser(0.6, 1.4);
  hrsp->Draw();
  c->cd(2);
  gPad->SetLogy();
  hrsp->GetXaxis()->SetRangeUser(0, 2);
  hrsp->Draw();

But in both pad I have the range [0, 2]. Is there something to disabled…?

Regards

Try:

TCanvas *c = new TCanvas("c", "", 700, 700);
c->Divide(1,2);
c->cd(1);
hrsp->GetXaxis()->SetRangeUser(0.6, 1.4);
hrsp->Draw();
c->cd(2);
gPad->SetLogy();
hrsp->DrawClone()->GetXaxis()->SetRangeUser(0, 2);

Dear Couet,

in ROOT 6.02/05, when I used: hrsp->DrawClone()->GetXaxis()->SetRangeUser(0, 2);
I have this error message:

error: no member
named ‘GetXaxis’ in 'TObject’
hrsp->DrawClone()->GetXaxis()->SetRangeUser(0, 2);
~~~~~~~~~~~~~~~~~ ^

Do you know what is wrong?

Regards

I did just a quick reply to show you that you need to clone the histogram in order to have 2 different ranges. The range is attached to the histogram. So try (assuming that hrs is for instance a TH1D*):

TH1D* h2 = (TH1D*) hrsp->DrawClone();
h2->GetXaxis()->SetRangeUser(0, 2);

Dear Couet,

ok, thank you for your answer, it worked.

Regards