User Tools

Site Tools


root:setaxisrange

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
root:setaxisrange [2010/11/09 16:08] – created nchiaproot:setaxisrange [2014/03/11 10:20] (current) – [X Axis of TGraph] add missing call to GetXaxis nchiap
Line 1: Line 1:
 ====== Set Display Range of Axis ====== ====== Set Display Range of Axis ======
 +The normal way to change the display range of an axis is:
 <code C++> <code C++>
 histogram->GetYaxis()->SetRangeUser(lower,upper); histogram->GetYaxis()->SetRangeUser(lower,upper);
 </code> </code>
 +
 +but there are several situations where this fails. See below for help in these cases.
 +
 +===== Y Axis of a normalized Histogram =====
 +Assume you have a histogram which has been normalized it with 
 +<code c++>
 +hist->SetNormFactor(1)
 +</code>
 +Your Y-axis will show values between 0 and 1. 
 +Trying to set the Y range using these values, eg. 
 +<code c++>SetRangeUser(0.01, 0.2)</code>
 +will fail however.
 +You still need to give the range in the original unnormalized units.
 +
 +You can scale normalized units back with:
 +<code C++>
 +Double_t scaleY = hist->GetEntries()/hist->GetNormFactor();
 +hist->GetYaxis()->SetRangeUser(normalizedLower*scaleY,normalizedUppe*scaleY);
 +</code>
 +
 +===== Y Axis of a THStack =====
 +Do not try to ''SetLimits'' or ''SetRangeUser'' of any histogram.
 +Instead use the following code:
 +<code c++>
 +THStack *hs = new THStack("hs","test stacked histograms");
 +hs->SetMinimum(0.);
 +hs->SetMaximum(10.);
 +</code>
 +
  
 ===== X Axis of TGraph ===== ===== X Axis of TGraph =====
Line 12: Line 42:
 TGraph* myGraph = new TGraph(); TGraph* myGraph = new TGraph();
 ... ...
-myGraph->SetLimits(lower,upper);+myGraph->GetXaxis()->SetLimits(lower,upper);
 </code> </code>
  
  
root/setaxisrange.1289315327.txt.gz · Last modified: 2010/11/09 16:08 by nchiap