Logo ROOT   6.12/07
Reference Guide
reverseaxis.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Example showing an histogram with reverse axis.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Olivier Couet
10 
11 void ReverseXAxis (TH1 *h);
12 void ReverseYAxis (TH1 *h);
13 
14 void reverseaxis()
15 {
16  TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
17  Float_t px, py;
18  TRandom r;
19  for (Int_t i = 0; i < 25000; i++) {
20  r.Rannor(px,py);
21  hpxpy->Fill(px,py);
22  }
23  TCanvas *c1 = new TCanvas("c1");
24  hpxpy->Draw("colz");
25  ReverseXAxis(hpxpy);
26  ReverseYAxis(hpxpy);
27 }
28 
29 void ReverseXAxis(TH1 *h)
30 {
31  // Remove the current axis
32  h->GetXaxis()->SetLabelOffset(999);
33  h->GetXaxis()->SetTickLength(0);
34 
35  // Redraw the new axis
36  gPad->Update();
37  TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
38  gPad->GetUymin(),
39  gPad->GetUxmin(),
40  gPad->GetUymin(),
41  h->GetXaxis()->GetXmin(),
42  h->GetXaxis()->GetXmax(),
43  510,"-");
44  newaxis->SetLabelOffset(-0.03);
45  newaxis->Draw();
46 }
47 
48 void ReverseYAxis(TH1 *h)
49 {
50  // Remove the current axis
51  h->GetYaxis()->SetLabelOffset(999);
52  h->GetYaxis()->SetTickLength(0);
53 
54  // Redraw the new axis
55  gPad->Update();
56  TGaxis *newaxis = new TGaxis(gPad->GetUxmin(),
57  gPad->GetUymax(),
58  gPad->GetUxmin()-0.001,
59  gPad->GetUymin(),
60  h->GetYaxis()->GetXmin(),
61  h->GetYaxis()->GetXmax(),
62  510,"+");
63  newaxis->SetLabelOffset(-0.03);
64  newaxis->Draw();
65 }
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:481
float Float_t
Definition: RtypesCore.h:53
return c1
Definition: legend1.C:41
TH1 * h
Definition: legend2.C:5
int Int_t
Definition: RtypesCore.h:41
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels The distance is expressed in per cent of the pad width...
Definition: TAttAxis.cxx:193
Double_t GetXmin() const
Definition: TAxis.h:133
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2969
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:249
The axis painter class.
Definition: TGaxis.h:24
TAxis * GetYaxis()
Definition: TH1.h:316
The Canvas class.
Definition: TCanvas.h:31
void SetLabelOffset(Float_t labeloffset)
Definition: TGaxis.h:107
The TH1 histogram class.
Definition: TH1.h:56
#define gPad
Definition: TVirtualPad.h:285
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length The length is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:280
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:291
Double_t GetXmax() const
Definition: TAxis.h:134
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315