Zoom Histogram

Changing the Range on the X-Axis of a Histogram

Image produced by .x ZoomHistogram.C

This demonstrates how to zoom into a histogram by changing the range on one of the axes (or both).

Author: Advait Dhingra
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Thursday, May 19, 2022 at 08:19 AM.

In [1]:
TH1F *orig = new TH1F("Normal Histogram", "Normal Histogram", 100, 0, 100);

for (int i = 0; i < 100; ++i) {
  Double_t x = gRandom->Gaus(50, 10);
  orig->Fill(x);
}

TH1F *zoom = (TH1F *)orig->Clone("zoom");
zoom->SetTitle("Zoomed-in Histogram");
zoom->GetXaxis()->SetRangeUser(50, 100);

TCanvas *c1 = new TCanvas("c1", "Histogram", 1500, 700);
c1->Divide(2, 1);

c1->cd(1);
orig->Draw();
c1->cd(2);
zoom->Draw();

Draw all canvases

In [2]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()