ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
legend1.C
Go to the documentation of this file.
1 {
2  TCanvas *c1 = new TCanvas("c1","c1",600,500);
3  gStyle->SetOptStat(0);
4 
5  TH1F *h1 = new TH1F("h1","TLegend Example",200,-10,10);
6  h1->FillRandom("gaus",30000);
7  h1->SetFillColor(kGreen);
8  h1->SetFillStyle(3003);
9  h1->Draw();
10 
11  TF1 *f1=new TF1("f1","1000*TMath::Abs(sin(x)/x)",-10,10);
12  f1->SetLineColor(kBlue);
13  f1->SetLineWidth(4);
14  f1->Draw("same");
15 
16  const Int_t n = 20;
17  Double_t x[n], y[n], ex[n], ey[n];
18  for (Int_t i=0;i<n;i++) {
19  x[i] = i*0.1;
20  y[i] = 1000*sin(x[i]+0.2);
21  x[i] = 17.8*x[i]-8.9;
22  ex[i] = 1.0;
23  ey[i] = 10.*i;
24  }
25  TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey);
26  gr->SetName("gr");
27  gr->SetLineColor(kRed);
28  gr->SetLineWidth(2);
29  gr->SetMarkerStyle(21);
30  gr->SetMarkerSize(1.3);
31  gr->SetMarkerColor(7);
32  gr->Draw("P");
33 
34  leg = new TLegend(0.1,0.7,0.48,0.9);
35  leg->SetHeader("The Legend Title");
36  leg->AddEntry(h1,"Histogram filled with random numbers","f");
37  leg->AddEntry("f1","Function abs(#frac{sin(x)}{x})","l");
38  leg->AddEntry("gr","Graph with error bars","lep");
39  leg->Draw();
40 
41  return c1;
42 }
43 
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
TCanvas * c1
Definition: legend1.C:2
Definition: Rtypes.h:61
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
int Int_t
Definition: RtypesCore.h:41
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1052
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
Definition: Rtypes.h:61
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
double sin(double)
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
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
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
leg
Definition: legend1.C:34
1-Dim function class
Definition: TF1.h:149
A TGraphErrors is a TGraph with error bars.
Definition: TGraphErrors.h:28
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1252
Definition: Rtypes.h:61
const Int_t n
Definition: legend1.C:16