# Incorrect legend displayed

**URL:** <https://root-forum.cern.ch/t/incorrect-legend-displayed/35480>\
**Category:** Newbie\
**Created:** [August 3, 2019, 1:31am UTC](https://root-forum.cern.ch/t/incorrect-legend-displayed/35480 "2019-08-03T01:31:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diwakar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/2acd7d/32.png) [@diwakar](https://root-forum.cern.ch/u/diwakar)\
**Post date:** [August 3, 2019, 1:31am UTC](https://root-forum.cern.ch/t/incorrect-legend-displayed/35480/1 "2019-08-03T01:31:37Z")

</div>

I am plotting two histograms together. One histogram is plotted in black line and the other in red line. But the legend shows black color for both the histograms. The relevant part of my script is below. I have also uploaded the plot i get.

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’  
TFile\* file = new TFile(“cpangle\_comb.root”);  
TH1F\* h\_phistar\_combined\_Even = (TH1F\*)file-\>Get(“h\_phistar\_combined\_Even”);  
TH1F\* h\_phistar\_combined\_Odd = (TH1F\*)file-\>Get(“h\_phistar\_combined\_Odd”);  
TH1F\* h\_phistar\_combined\_DY = (TH1F\*)file-\>Get(“h\_phistar\_combined\_DY”);  
TH1F\* h\_phistar\_combined\_Even\_normalised = (TH1F\*)h\_phistar\_combined\_Even-\>Clone();  
h\_phistar\_combined\_Even\_normalised-\>Divide(h\_phistar\_combined\_DY);  
TH1F\* h\_phistar\_combined\_Odd\_normalised = (TH1F\*)h\_phistar\_combined\_Odd-\>Clone();  
h\_phistar\_combined\_Odd\_normalised-\>Divide(h\_phistar\_combined\_DY);  
TCanvas\* c = new TCanvas();  
h\_phistar\_combined\_Even\_normalised-\>SetLineColor(1);  
h\_phistar\_combined\_Even\_normalised-\>Draw();  
h\_phistar\_combined\_Even\_normalised-\>SetAxisRange(8., 22.,“Y”);  
h\_phistar\_combined\_Odd\_normalised-\>SetLineColor(2);  
h\_phistar\_combined\_Odd\_normalised-\>Draw(“same”);  
h\_phistar\_combined\_Odd\_normalised-\>SetAxisRange(8., 22.,“Y”);  
TLegend\* leg\_normalised = new TLegend(0.3,0.8,0.48,0.9);  
leg\_normalised-\>AddEntry(“h\_phistar\_combined\_Even\_normalised”,“Even”);  
leg\_normalised-\>AddEntry(“h\_phistar\_combined\_Odd\_normalised”,“Odd”);  
leg\_normalised-\>Draw();  
c-\>SaveAs(“test.pdf”);

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’  
[test.pdf](https://root-forum.cern.ch/uploads/short-url/utH8qmAqOf1jOAUxIqvLkTILpMh.pdf) (13.4 KB)

---

<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:** [August 3, 2019, 7:40am UTC](https://root-forum.cern.ch/t/incorrect-legend-displayed/35480/2 "2019-08-03T07:40:07Z")

</div>

Try:

```auto
leg_normalised->AddEntry(h_phistar_combined_Even_normalised, "Even");
leg_normalised->AddEntry(h_phistar_combined_Odd_normalised, "Odd");

```

---

<div class="post-metadata">

**Author:** ![diwakar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/2acd7d/32.png) [@diwakar](https://root-forum.cern.ch/u/diwakar)\
**Post date:** [August 3, 2019, 9:30am UTC](https://root-forum.cern.ch/t/incorrect-legend-displayed/35480/3 "2019-08-03T09:30:21Z")

</div>

Worked perfectly. Thank you. I do not understand it though because i had always put the histogram name in quotes and it always plotted legend correctly.

---

<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:** [August 3, 2019, 9:41am UTC](https://root-forum.cern.ch/t/incorrect-legend-displayed/35480/4 "2019-08-03T09:41:02Z")

</div>

As long as “histogram names” correspond to “histogram pointers”, it will be fine.
