PyROOT: TLegend vanishes when clicking on canvas

Hello,
I created a TLegend in PyROOT it displays fine in the canvas but when I want to interact with the canvas (e.g simply clicking on the canvas) the legend vanishes. I tried leg.DrawClone() with no difference.
Any ideas what I am doing wrong?

Thanks,
Sebastien

leg = TLegend(.63,.62,.97,.93)
leg.SetBorderSize(0)
leg.SetFillColor(0)
leg.SetFillStyle(0)
leg.SetTextFont(42)
leg.SetTextSize(0.035)
leg.SetHeader("prim. photon energy","C")
leg.AddEntry(hLStep[idx_1],"40 keV")
leg.AddEntry(hLStep[idx_2],"110 keV")
leg.AddEntry(hLStep[idx_3],"290 keV")


#step length histo
c1= TCanvas("c1","c1",200, 10, 1200, 500)
#c1.Divide(2)
c1.cd()
c1.SetLogy()
hLStep[idx_1].Draw("hist")
hLStep[idx_2].Draw("hist,same")
hLStep[idx_2].SetLineColor(kBlue)
hLStep[idx_3].Draw("hist,same")
hLStep[idx_3].SetLineColor(kRed)
leg.Draw()
c1.Update()

ROOT.gApplication.Run()

ROOT Version: 6.10.08
Platform: mac OS 10.13.6
Compiler: none (Python)


may be @etejedor can help.

Hi @smurphy,

Could you provide the entire script so I can try to reproduce?

On the other hand, how to you run this script? Do you use the python -i flag to keep the Python interpreter alive (and thus your canvas)?

Cheers,
Enric

Hi,

Thanks for the answers.

So I realised that later in the code I was re-defining a TLegend with exactly the same name (leg) and drawing it on another canvas. That obviously caused memory problems.
I renamed the second one and it works (stops vanishing).

Cheers,
Sebastien

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.