# Legend for THStack

**URL:** <https://root-forum.cern.ch/t/legend-for-thstack/47322>\
**Category:** Newbie\
**Created:** [October 20, 2021, 9:44am UTC](https://root-forum.cern.ch/t/legend-for-thstack/47322 "2021-10-20T09:44:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenith378](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zenith378/32/31705_2.png) [@zenith378](https://root-forum.cern.ch/u/zenith378)\
**Post date:** [October 20, 2021, 9:44am UTC](https://root-forum.cern.ch/t/legend-for-thstack/47322/1 "2021-10-20T09:44:24Z")

</div>

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](https://root-forum.cern.ch/uploads/short-url/iLYkiQwDNUiJLQpQIaTD6tu1smD.pdf) (16.3 KB)

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

```auto
    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

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 20, 2021, 9:54am UTC](https://root-forum.cern.ch/t/legend-for-thstack/47322/2 "2021-10-20T09:54:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [October 20, 2021, 10:03am UTC](https://root-forum.cern.ch/t/legend-for-thstack/47322/3 "2021-10-20T10:03:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenith378](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zenith378/32/31705_2.png) [@zenith378](https://root-forum.cern.ch/u/zenith378)\
**Post date:** [October 20, 2021, 10:05am UTC](https://root-forum.cern.ch/t/legend-for-thstack/47322/4 "2021-10-20T10:05:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 20, 2021, 10:13am UTC](https://root-forum.cern.ch/t/legend-for-thstack/47322/5 "2021-10-20T10:13:46Z")

</div>

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