ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
reverseaxis.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// Example showing an histogram with reverse axis.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Olivier Couet
9 
10 void ReverseXAxis (TH1 *h);
11 void ReverseYAxis (TH1 *h);
12 
13 void reverseaxis ()
14 {
15  TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
16  Float_t px, py;
17  TRandom r;
18  for (Int_t i = 0; i < 25000; i++) {
19  r.Rannor(px,py);
20  hpxpy->Fill(px,py);
21  }
22  TCanvas *c1 = new TCanvas("c1");
23  hpxpy->Draw("colz");
24  ReverseXAxis(hpxpy);
25  ReverseYAxis(hpxpy);
26 }
27 
28 void ReverseXAxis (TH1 *h)
29 {
30  // Remove the current axis
31  h->GetXaxis()->SetLabelOffset(999);
32  h->GetXaxis()->SetTickLength(0);
33 
34  // Redraw the new axis
35  gPad->Update();
36  TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
37  gPad->GetUymin(),
38  gPad->GetUxmin(),
39  gPad->GetUymin(),
40  h->GetXaxis()->GetXmin(),
41  h->GetXaxis()->GetXmax(),
42  510,"-");
43  newaxis->SetLabelOffset(-0.03);
44  newaxis->Draw();
45 }
46 
47 void ReverseYAxis (TH1 *h)
48 {
49  // Remove the current axis
50  h->GetYaxis()->SetLabelOffset(999);
51  h->GetYaxis()->SetTickLength(0);
52 
53  // Redraw the new axis
54  gPad->Update();
55  TGaxis *newaxis = new TGaxis(gPad->GetUxmin(),
56  gPad->GetUymax(),
57  gPad->GetUxmin()-0.001,
58  gPad->GetUymin(),
59  h->GetYaxis()->GetXmin(),
60  h->GetYaxis()->GetXmax(),
61  510,"+");
62  newaxis->SetLabelOffset(-0.03);
63  newaxis->Draw();
64 }
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:460
float Float_t
Definition: RtypesCore.h:53
int Int_t
Definition: RtypesCore.h:41
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
Float_t py
Definition: hprod.C:33
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:176
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:29
Double_t GetXmin() const
Definition: TAxis.h:137
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
The axis painter class.
Definition: TGaxis.h:39
TAxis * GetYaxis()
Definition: TH1.h:320
The Canvas class.
Definition: TCanvas.h:48
void SetLabelOffset(Float_t labeloffset)
Definition: TGaxis.h:117
Double_t GetXmax() const
Definition: TAxis.h:138
The TH1 histogram class.
Definition: TH1.h:80
Float_t px
Definition: hprod.C:33
#define gPad
Definition: TVirtualPad.h:288
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:232
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:287
TAxis * GetXaxis()
Definition: TH1.h:319