int macro_TLegend () { gStyle->SetOptStat (0); TH1F* h1 = new TH1F ("h1", "TLegend Example", 200,-14,10); h1->FillRandom ("gaus", 30000); h1->SetFillColor (18); h1->Draw (); TF1* f1 = new TF1 ("f1", "1000*abs(sin(x)/x)", -14, 14); f1->SetLineColor (kBlue); f1->Draw ("same"); Int_t i = 0; Double_t x[50], y[50], ex[50], ey[50]; for (Double_t xval = -9; xval <= 9; xval++, i++) { x[i] = xval; y[i] = 1000 * sin ( (xval + 9)/10 ) ; ex[i] = 0.3; ey[i] = (xval+9) * 3 ; } TGraphErrors* gr = new TGraphErrors (i, x, y, ex, ey); gr->SetName ("gr"); gr->SetMarkerStyle (21); gr->SetMarkerColor (kRed); gr->Draw ("P"); TLegend* leg = new TLegend (0.1, 0.6, 0.48, 0.9); leg->SetHeader ("The Legend Title"); leg->AddEntry ( h1 ,"Histogram filled randomly" , "f" ); leg->AddEntry ("f1","Function abs(#frac{sin(x)}{x})", "l" ); leg->AddEntry ("gr","Graph with errors" , "lep"); leg->AddEntry ((TObject*)0, "Just some text", ""); leg->Draw (); return 0; }