Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
legend1.C
Go to the documentation of this file.
1{
2 TCanvas *c1 = new TCanvas("c1","c1",600,500);
4
5 TH1F *h1 = new TH1F("h1","TLegend Example",200,-10,10);
6 h1->FillRandom("gaus",30000);
9 h1->Draw();
10
11 TF1 *f1=new TF1("f1","1000*TMath::Abs(sin(x)/x)",-10,10);
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 }
26 gr->SetName("gr");
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
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:39
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:45
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:233
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF1.cxx:1333
A TGraphErrors is a TGraph with error bars.
void SetName(const char *name="") override
Set graph name.
Definition TGraph.cxx:2381
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:831
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:622
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3519
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
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:1640
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
Double_t ey[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
Double_t ex[n]
Definition legend1.C:17
TH1F * h1
Definition legend1.C:5
TF1 * f1
Definition legend1.C:11
leg
Definition legend1.C:34