Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 }