TCanvas SetRange


ROOT Version: 6.16
Platform: Fedora
Compiler: Emacs


I am running a code, and I have a final output histogram on the canvas. I need to zoom the range on X-axis from 1800 to 2100s. I do "sce->GetXaxis()->SetRangeUser(1800,2100);
" and I get an error "error: no member named ‘GetXaxis’ in ‘TCanvas’ " Any ideas how can I zoom that range?

TCanvas *newtry() {
THStack hs = new THStack(“hs”,“sce”);
TFile f1 = TFile::Open(“hists10153_blinded.root”);
TH1F
sc10153 = (TH1F
)f1->Get(“sc10153;1”);
hs->Add(sc10153);

TFile f2 = TFile::Open(“hists10711_blinded.root”);
TH1F
sc10711 = (TH1F*)f2->Get(“sc10711;1”);
hs->Add(sc10711);

TFile f3 = TFile::Open(“hists12797_blinded.root”);
TH1F
sc12797 = (TH1F*)f3->Get(“sc12797;1”);
hs->Add(sc12797);

TCanvas *sce = new TCanvas(“sce”,“stackedstacked hists”,10,10,700,700);
sce;
sce->cd(1);
hs->Draw();
return sce;
}

The axis belongs to the histogram, not to the canvas. Try something like
myhisto->GetXaxis()->SetRangeUser...

hs->GetXaxis()->SetRangeUser(1800., 2100.);

1 Like

Thank you! It works.

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