Can TLegend object be added to a TMultiGraph object plotting?

I want to add a TLegend object to a TMultiGraph object, but i seems not work, here is the key code:

    TLegend* lg1=new TLegend(0.1,0.7,0.3,0.9,"Scattering and Efficiency Correction");
    lg1->SetFillColor(0);
    lg1->AddEntry(mg1,"Cal Data");
    lg1->AddEntry(gr1,"Efficiency");
    lg1->AddEntry(gr2,"Correction");
    lg1->DrawClone("same");

ROOT Version: 6.24/02
Platform: Ubuntu 20.04
Compiler: GCC 9.3.0


It’s unclear what you do. Try:

TCanvas *c = new TCanvas("c", "c");
mg1->Draw("AL");
gr1->Draw("P");
gr2->Draw("P")'
lg1->Draw();
c->SaveAs("c.png");

Add also:

  TLegend* lg1=new TLegend(0.1,0.7,0.3,0.9,"Scattering and Efficiency Correction");
    lg1->SetFillColor(0);
    lg1->AddEntry(mg1,"Cal Data");
    lg1->AddEntry(gr1,"Efficiency");
    lg1->AddEntry(gr2,"Correction");

Before drawing the legend.

You can also use BuildLegend instead.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.