Logo ROOT   6.14/05
Reference Guide
labels1.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook
4 /// Setting alphanumeric labels in a 1-d histogram.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Rene Brun
10 
11 void labels1()
12 {
13  Int_t i;
14  const Int_t nx = 20;
15  const char *people[nx] = {"Jean","Pierre","Marie","Odile",
16  "Sebastien","Fons","Rene","Nicolas","Xavier","Greg",
17  "Bjarne","Anton","Otto","Eddy","Peter","Pasha",
18  "Philippe","Suzanne","Jeff","Valery"};
19  TCanvas *c1 = new TCanvas("c1","demo bin labels",10,10,900,500);
20  c1->SetGrid();
21  c1->SetBottomMargin(0.15);
22  TH1F *h = new TH1F("h","test",nx,0,nx);
23  h->SetFillColor(38);
24  for (i=0;i<5000;i++) h->Fill(gRandom->Gaus(0.5*nx,0.2*nx));
25  h->SetStats(0);
26  for (i=1;i<=nx;i++) h->GetXaxis()->SetBinLabel(i,people[i-1]);
27  h->Draw();
28  TPaveText *pt = new TPaveText(0.6,0.7,0.98,0.98,"brNDC");
29  pt->SetFillColor(18);
30  pt->SetTextAlign(12);
31  pt->AddText("Use the axis Context Menu LabelsOption");
32  pt->AddText(" \"a\" to sort by alphabetic order");
33  pt->AddText(" \">\" to sort by decreasing values");
34  pt->AddText(" \"<\" to sort by increasing values");
35  pt->Draw();
36 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3251
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:233
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:256
return c1
Definition: legend1.C:41
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:285
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:182
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
int Int_t
Definition: RtypesCore.h:41
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:327
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
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:2974
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
#define h(i)
Definition: RSha256.hxx:106
The Canvas class.
Definition: TCanvas.h:31
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:809
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8284
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315