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)
12{
13 // Remove the current axis
14 h->GetXaxis()->SetLabelOffset(999);
15 h->GetXaxis()->SetTickLength(0);
16
17 // Redraw the new axis
18 auto newxaxis = new TGaxis(gPad->GetUxmax(),
19 gPad->GetUymin(),
20 gPad->GetUxmin(),
21 gPad->GetUymin(),
22 h->GetXaxis()->GetXmin(),
23 h->GetXaxis()->GetXmax(),
24 510,"-");
25 newxaxis->SetLabelOffset(-0.03);
26 newxaxis->Draw();
27}
28
29void ReverseYAxis(TH1 *h)
30{
31 // Remove the current axis
32 h->GetYaxis()->SetLabelOffset(999);
33 h->GetYaxis()->SetTickLength(0);
34
35 // Redraw the new axis
36 auto newyaxis = new TGaxis(gPad->GetUxmin(),
37 gPad->GetUymax(),
38 gPad->GetUxmin(),
39 gPad->GetUymin(),
40 h->GetYaxis()->GetXmin(),
41 h->GetYaxis()->GetXmax(),
42 510,"+R");
43 newyaxis->SetLabelOffset(0.01);
44 newyaxis->Draw();
45}
46
47void reverseaxis()
48{
49 TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
50 Float_t px, py;
51 TRandom r;
52 for (Int_t i = 0; i < 25000; i++) {
53 r.Rannor(px,py);
54 hpxpy->Fill(px,py);
55 }
56 TCanvas *c1 = new TCanvas("c1");
57 hpxpy->Draw("colz");
58 c1->Update();
59 ReverseXAxis(hpxpy);
60 ReverseYAxis(hpxpy);
61}
62
#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
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3068
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:308
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:393
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
return c1
Definition legend1.C:41