Legend for THStack

Hi everyone,
I’d like to make a legend for the plot of my stacked histograms using TLegend but i am having trouble placing it. I tried to search the documentation but I couldn’t find what the arguments of the TLegend are. Anyone could explain to me what they mean?

I also have another problem. When I plot my stacked histogram the legend of the single histogram (hRie in the attached figure) remains in the top right corner. I’d like to remove it. Anyone knows how i could do it?

Electron_pT_stacked_RctIso.pdf (16.3 KB)

I also attach a snippet of my code as well. Thanks in advance for the help.

    d[0]->cd();
    hs[7]->Draw();
    hs[7]->GetXaxis()->SetTitle("p_{T} [GeV]");
    hs[7]->GetYaxis()->SetTitle("Events/GeV");

    auto legend_ele = new TLegend(0.9,0.7,0.48,0.9);
    legend_ele->AddEntry(hRi[0],"Electron Events","f");
    legend_ele->AddEntry(hRi[2],"Muon Events","f");
    legend_ele->AddEntry(hRi[4],"Tau Events","f");
    legend_ele->Draw();

    d[0]->Modified();

ROOT Version: 6.11/02


Try: TLegend(0.6, 0.5, 0.9, 0.7); // (x1, y1, x2, y2)

1 Like

TLegend documentation of coordinates:
https://root.cern/doc/v608/classTLegend.html#a1f4a3d8b87bcbaea924470e8df416aaa

1 Like

Thanks for the quick replies! I surely understand better now and I was able to plage the Legend where I want it.
I still have the problem about the legend of the single histogram (in the attached file hRiee, the one with numeber of entries, mean and standard deviation). Anyone knows how to remove that?

hs[7]->SetStats(kFALSE); // no statistics box