Logo ROOT   6.07/09
Reference Guide
labels2.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook
4 /// Setting alphanumeric labels.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Rene Brun
10 
11 void labels2()
12 {
13  Int_t i;
14  const Int_t nx = 12;
15  const Int_t ny = 20;
16  const char *month[nx] = {"January","February","March","April",
17  "May","June","July","August","September","October",
18  "November","December"};
19  const char *people[ny] = {"Jean","Pierre","Marie","Odile",
20  "Sebastien","Fons","Rene","Nicolas","Xavier","Greg",
21  "Bjarne","Anton","Otto","Eddy","Peter","Pasha",
22  "Philippe","Suzanne","Jeff","Valery"};
23  TCanvas *c1 = new TCanvas("c1","demo bin labels",
24  10,10,800,800);
25  c1->SetGrid();
26  c1->SetLeftMargin(0.15);
27  c1->SetBottomMargin(0.15);
28  TH2F *h = new TH2F("h","test",nx,0,nx,ny,0,ny);
29  for (i=0;i<5000;i++) {
30  h->Fill(gRandom->Gaus(0.5*nx,0.2*nx),
31  gRandom->Gaus(0.5*ny,0.2*ny));
32  }
33  h->SetStats(0);
34  for (i=1;i<=nx;i++) h->GetXaxis()->SetBinLabel(i,month[i-1]);
35  for (i=1;i<=ny;i++) h->GetYaxis()->SetBinLabel(i,people[i-1]);
36  h->Draw("text");
37 
38  TPaveText *pt = new TPaveText(0.6,0.85,0.98,0.98,"brNDC");
39  pt->SetFillColor(18);
40  pt->SetTextAlign(12);
41  pt->AddText("Use the axis Context Menu LabelsOption");
42  pt->AddText(" \"a\" to sort by alphabetic order");
43  pt->AddText(" \">\" to sort by decreasing values");
44  pt->AddText(" \"<\" to sort by increasing values");
45  pt->Draw();
46 }
const int nx
Definition: kalman.C:16
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:211
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
return c1
Definition: legend1.C:41
TH1 * h
Definition: legend2.C:5
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:160
int Int_t
Definition: RtypesCore.h:41
const int ny
Definition: kalman.C:17
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:318
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:47
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:100
TPaveText * pt
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2853
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
tomato 2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:255
TAxis * GetYaxis()
Definition: TH1.h:325
R__EXTERN TRandom * gRandom
Definition: TRandom.h:66
The Canvas class.
Definition: TCanvas.h:41
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:27
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:808
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:308
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8058
TAxis * GetXaxis()
Definition: TH1.h:324
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition: TAttPad.cxx:110