Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
gr111_legend.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Simple graph with legend.

For more details on TLegend see documentation

void gr111_legend() {
auto c = new TCanvas("c","", 900, 800);
c->SetGrid();
const Int_t n = 5;
Double_t x[n] = {-3.00, -2.68, -2.36, -2.05, -1.73};
Double_t y1[n] = {-0.98, -0.89, -0.71, -0.46, -0.16};
Double_t y2[n] = {-2.98, -2.89, -2.71, -2.46, -2.16};
TGraph *gr1 = new TGraph(n, x, y1); //Create the graph
gr1->SetLineColor(2);
gr1->SetLineWidth(4);
gr1->SetMarkerColor(4);
gr1->SetMarkerStyle(21);
gr1->SetTitle("Graph with legend");
TLegend *legend = new TLegend(0.1,0.7,0.38,0.9); //Create the TLegend object and define it's position
legend->SetHeader("Legend title", "C"); //"C" Center alignment for the header ("L" Left and "R" Right)
legend->SetFillColor(kWhite);
legend->SetBorderSize(1);
legend->SetTextSize(0.04);
legend->AddEntry(gr1, "Data points", "lp"); // "p" for point marker, "l" for line, "e" for error bars if TGraphError is used.
gr1->Draw("");
// Draw the legend
legend->Draw();
}
#define c(i)
Definition RSha256.hxx:101
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kWhite
Definition Rtypes.h:65
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
The Canvas class.
Definition TCanvas.h:23
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Date
25/11/2024
Author
Emanuele Chiamulera

Definition in file gr111_legend.C.