Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
11void labels1()
12{
13 Int_t i;
14 const Int_t nx = 20;
15 const char *people[nx] = {"Jean", "Pierre", "Marie", "Odile", "Sebastien", "Fons", "Rene",
16 "Nicolas", "Xavier", "Greg", "Bjarne", "Anton", "Otto", "Eddy",
17 "Peter", "Pasha", "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++)
24 h->Fill(gRandom->Gaus(0.5 * nx, 0.2 * nx));
25 h->SetStats(0);
26 for (i = 1; i <= nx; i++)
27 h->GetXaxis()->SetBinLabel(i, people[i - 1]);
28 h->Draw();
29 TPaveText *pt = new TPaveText(0.6, 0.7, 0.98, 0.98, "brNDC");
30 pt->SetFillColor(18);
31 pt->SetTextAlign(12);
32 pt->AddText("Use the axis Context Menu LabelsOption");
33 pt->AddText(" \"a\" to sort by alphabetic order");
34 pt->AddText(" \">\" to sort by decreasing values");
35 pt->AddText(" \"<\" to sort by increasing values");
36 pt->Draw();
37}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:42
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
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:275
TPaveText * pt
return c1
Definition legend1.C:41