Logo ROOT  
Reference Guide
reverseaxis.C File Reference

Detailed Description

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

void ReverseXAxis (TH1 *h);
void ReverseYAxis (TH1 *h);
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");
ReverseXAxis(hpxpy);
ReverseYAxis(hpxpy);
}
void ReverseXAxis(TH1 *h)
{
// Remove the current axis
h->GetXaxis()->SetLabelOffset(999);
h->GetXaxis()->SetTickLength(0);
// Redraw the new axis
gPad->Update();
TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
gPad->GetUymin(),
gPad->GetUxmin(),
gPad->GetUymin(),
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
510,"-");
newaxis->SetLabelOffset(-0.03);
newaxis->Draw();
}
void ReverseYAxis(TH1 *h)
{
// Remove the current axis
h->GetYaxis()->SetLabelOffset(999);
h->GetYaxis()->SetTickLength(0);
// Redraw the new axis
gPad->Update();
TGaxis *newaxis = new TGaxis(gPad->GetUxmin(),
gPad->GetUymax(),
gPad->GetUxmin()-0.001,
gPad->GetUymin(),
h->GetYaxis()->GetXmin(),
h->GetYaxis()->GetXmax(),
510,"+");
newaxis->SetLabelOffset(-0.03);
newaxis->Draw();
}
Author
Olivier Couet

Definition in file reverseaxis.C.

TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
r
ROOT::R::TRInterface & r
Definition: Object.C:4
Float_t
float Float_t
Definition: RtypesCore.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
TGaxis::SetLabelOffset
void SetLabelOffset(Float_t labeloffset)
Definition: TGaxis.h:106
TRandom
Definition: TRandom.h:27
h
#define h(i)
Definition: RSha256.hxx:124
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
TCanvas
Definition: TCanvas.h:23
TGaxis
Definition: TGaxis.h:23
TH1
Definition: TH1.h:57
gPad
#define gPad
Definition: TVirtualPad.h:287
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
c1
return c1
Definition: legend1.C:41