2 graphs and 1 legend but with no colours

Hi,

I would be very grateful for any advice in drawing the legend correctly. I am plotting two graphs with different colours but the legend text appears in black. The script I am using is:

int plot() {

TFile* file = TFile::Open(“graph.root”);
TGraph* gr = (TGraph*)(file->Get(“Sim”));
TGraphErrors* gr_file = (TGraphErrors*)(file->Get(“Data”));

TCanvas* c = new TCanvas();

gr->SetMarkerColor(kRed);
gr->SetLineColor(kRed);
gr->SetLineWidth(2);
gr->Draw(“ALP”);

gr_file->SetMarkerColor(kBlue);
gr_file->SetLineColor(kBlue);
gr_file->Draw(“P”);

TLegend* leg = new TLegend(0.11,0.7,0.3,0.88);
leg->SetHeader(“Legend”);
leg->AddEntry(“gr”,“Sim”,“l”);
leg->AddEntry(“gr_file”,“Data”,“lep”);

leg->Draw();

return 0;

}

But no colours go into the legend. I attached the image (with very low statistics). Is there a way to solve this and have the colours in the legend drawn correctly?

Thank you,

Cristian


Either:
leg->AddEntry(gr, “my Sim line”, “l”);
leg->AddEntry(gr_file, “my Data points”, “lep”);
or:
leg->AddEntry(“Sim”, “my Sim line”, “l”);
leg->AddEntry(“Data”, “my Data points”, “lep”);

Of course! :blush: Thank you. :slight_smile: