ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
labels1.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// Setting alphanumeric labels in a 1-d histogram.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Rene Brun
9 
10 void labels1()
11 {
12  Int_t i;
13  const Int_t nx = 20;
14  const char *people[nx] = {"Jean","Pierre","Marie","Odile",
15  "Sebastien","Fons","Rene","Nicolas","Xavier","Greg",
16  "Bjarne","Anton","Otto","Eddy","Peter","Pasha",
17  "Philippe","Suzanne","Jeff","Valery"};
18  TCanvas *c1 = new TCanvas("c1","demo bin labels",10,10,900,500);
19  c1->SetGrid();
20  c1->SetBottomMargin(0.15);
21  TH1F *h = new TH1F("h","test",nx,0,nx);
22  h->SetFillColor(38);
23  for (i=0;i<5000;i++) h->Fill(gRandom->Gaus(0.5*nx,0.2*nx));
24  h->SetStats(0);
25  for (i=1;i<=nx;i++) h->GetXaxis()->SetBinLabel(i,people[i-1]);
26  h->Draw();
27  TPaveText *pt = new TPaveText(0.6,0.7,0.98,0.98,"brNDC");
28  pt->SetFillColor(18);
29  pt->SetTextAlign(12);
30  pt->AddText("Use the axis Context Menu LabelsOption");
31  pt->AddText(" \"a\" to sort by alphabetic order");
32  pt->AddText(" \">\" to sort by decreasing values");
33  pt->AddText(" \"<\" to sort by increasing values");
34  pt->Draw();
35 }
const int nx
Definition: kalman.C:16
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
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
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
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
int Int_t
Definition: RtypesCore.h:41
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:326
virtual void SetTextAlign(Short_t align=11)
Definition: TAttText.h:55
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:97
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
The Canvas class.
Definition: TCanvas.h:48
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:35
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:793
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8320
TAxis * GetXaxis()
Definition: TH1.h:319