Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
#define gPad
The Canvas class.
Definition TCanvas.h:23
The axis painter class.
Definition TGaxis.h:24
void SetLabelOffset(Float_t labeloffset)
Definition TGaxis.h:106
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3067
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:258
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:347
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
return c1
Definition legend1.C:41