Logo ROOT  
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
11void ReverseXAxis (TH1 *h);
12void ReverseYAxis (TH1 *h);
13
14void 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
29void 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
48void 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}
ROOT::R::TRInterface & r
Definition: Object.C:4
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
float Float_t
Definition: RtypesCore.h:53
#define gPad
Definition: TVirtualPad.h:286
The Canvas class.
Definition: TCanvas.h:31
The axis painter class.
Definition: TGaxis.h:24
void SetLabelOffset(Float_t labeloffset)
Definition: TGaxis.h:107
The TH1 histogram class.
Definition: TH1.h:56
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2998
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
return c1
Definition: legend1.C:41