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.

    hs[7]->GetXaxis()->SetTitle("p_{T} [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");


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:

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