Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist008_TH1_zoom.C File Reference

Detailed Description

View in nbviewer Open in SWAN
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).

{
// Create and fill a histogram
TH1F *orig = new TH1F("Normal Histogram", "Normal Histogram", 100, 0, 100);
for (int i = 0; i < 1000; ++i) {
double x = rng.Gaus(50, 10);
orig->Fill(x);
}
// Clone the histogram into one called "zoom"
TH1F *zoom = static_cast<TH1F *>(orig->Clone("zoom"));
zoom->SetTitle("Zoomed-in Histogram");
// "Zoom" in the histogram by setting a new range to the X axis
zoom->GetXaxis()->SetRangeUser(50, 100);
// Draw both histograms to a canvas
TCanvas *c1 = new TCanvas("c1", "Histogram", 1500, 700);
// split the canvas horizontally in 2
int nsubdivX = 2;
int nsubdivY = 1;
c1->Divide(nsubdivX, nsubdivY);
c1->cd(1);
orig->Draw();
c1->cd(2);
zoom->Draw();
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:645
Random number generator class based on M.
Definition TRandom3.h:27
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
Date
November 2024
Author
Advait Dhingra

Definition in file hist008_TH1_zoom.C.