Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
reverseaxis.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Example showing an histogram with reverse axis.

void ReverseXAxis(TH1 *h)
{
// Remove the current axis
h->GetXaxis()->SetLabelOffset(999);
h->GetXaxis()->SetTickLength(0);
// Redraw the new axis
auto newxaxis = new TGaxis(gPad->GetUxmax(),
gPad->GetUymin(),
gPad->GetUxmin(),
gPad->GetUymin(),
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
510,"-");
newxaxis->SetLabelOffset(-0.03);
newxaxis->Draw();
}
void ReverseYAxis(TH1 *h)
{
// Remove the current axis
h->GetYaxis()->SetLabelOffset(999);
h->GetYaxis()->SetTickLength(0);
// Redraw the new axis
auto newyaxis = new TGaxis(gPad->GetUxmin(),
gPad->GetUymax(),
gPad->GetUxmin(),
gPad->GetUymin(),
h->GetYaxis()->GetXmin(),
h->GetYaxis()->GetXmax(),
510,"+R");
newyaxis->SetLabelOffset(0.01);
newyaxis->Draw();
}
void reverseaxis()
{
TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
Float_t px, py;
for (Int_t i = 0; i < 25000; i++) {
r.Rannor(px,py);
hpxpy->Fill(px,py);
}
TCanvas *c1 = new TCanvas("c1");
hpxpy->Draw("colz");
c1->Update();
ReverseXAxis(hpxpy);
ReverseYAxis(hpxpy);
}
#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
Author
Olivier Couet

Definition in file reverseaxis.C.