Tlegend not showing up in pyRoot

Hello kind ROOT experts, hopefully this is just a stupid problem. But i am trying to get a Tlegend to show up in my output canvas which i save as a png or in a macro and neither works. Here is my code :

import math
import os
from glob import glob
from ROOT import *
import rootlogon
from pyroot_helpers import *
from plot_formatter import *
from ROOT import SetOwnership
.
.
.
c = TCanvas()
f = TFile(“npv.root”)
h_hnpv= get_hist(f,‘fakeRate_%s_%s’%(ratetype,central),’%s/MCsub_%s’%(dn_rates,central))
h_lnpv = get_hist(f,‘fakeRate_%s_%s’%(ratetype2,central),’%s/%s/MCsub_%s’%(plottype,ratetype2,central))

l = ROOT.TLegend(0.5,0.5,0.5,0.5)
SetOwnership( l, 0 ) # 0 = release (not keep), 1 = keep #Saw this on a previous root help post
l.SetLineColor(0)
l.SetFillColor(0)
l.SetShadowColor(0)
l.AddEntry(h_hnpv,‘FF with npv > 15’,‘l’)
l.AddEntry(h_lnpv,‘FF with npv < 15’,‘l’)

h_hnpv.Draw(‘p’)
h_lnpv.Draw(‘p,same’)
l.Draw(‘same’)

c.SaveAs(‘pup.C’)
#c.SaveAs(‘pup.png’)
f.Close()

As you can see i tried this SetOwnership function as i had seen someone else had a problem with thison ROOT Topics, but alas it did not work.

Cheers,
Anthony

You do not need the option “same” when you draw a legend. Just do:

l.Draw()

Hi couet,
Thanks, but this is what i was originally doing, but it does not solve the problem either.
Cheers,
Anthony

can you post the picture you get ?

Sure, here you are.


oops … yes the error is obvious … sorry to not have noticed earlier. You do:

l = ROOT.TLegend(0.5,0.5,0.5,0.5)

and the TLegend constructor is:

TLegend(Double_t x1, Double_t y1, Double_t x2, Double_t y2,....

So obviously your input values are wrong.

Ah thanks,
What a foolish mistake.
Sorry to waste your time and thanks,
Anthony