TLatex not drawing in pyRoot


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


The following code snippet does NOT result in the TLatex object being drawn, and I don’t understand why.

C1 = ROOT.TCanvas()
hist.Draw()
myLatex = ROOT.TLatex()
myLatex.SetNDC()
myLatex.DrawLatex(0.2, 0.4, “Some text here”)
myLatex.Draw(“SAME”)
C1.SaveAs(“someName.pdf”)

Code with this same form works on other TCanvases in the same script, but fails on this one particular canvas.

Does anyone have any ideas why this would be the case?

That code works well for me (supposing your hist exists and is drawn). One thing: remove myLatex.Draw(“SAME”), as “same” doesn’t exist for TLatex, and you already did DrawLatex anyway.
Try adding

C1.Modified()
C1.Update()

before saving the canvas (although in my case it works without these lines). Maybe also try gPad.Modified() and gPad.Update() instead.

Thanks a lot for your response, and thanks for telling me that the myLatex.Draw(“SAME”) is unnecessary! Unfortunately, none of those seem to do the trick. It’s very strange, code equivalent to this works in other places in the same script. I guess there is always the option of making a script just to draw this one canvas.

Thanks for your time!

Maybe you want: myLatex.DrawLatexNDC(0.2, 0.4, "Some text here")

Thanks a lot for writing back (also, great username!). Unfortunately, that didn’t do it either.

I appreciate your help. :slight_smile:

What if you only have these lines (plus opening the file and getting the histogram)? Do you still not get the text? If it works, start adding the rest of the code by parts and see where it fails. Or post all the related code.

{
   auto C1 = new TCanvas();
   auto hist = new TH1F("h","h",10, -100,0);
   hist->SetMaximum(3.14159);
   hist->SetMinimum(-3.14159);
   hist->Draw();
   auto myLatex = new TLatex();
   myLatex->DrawLatexNDC(0.2, 0.4, "Some text here");
}

Thanks for the hint (and sorry for my slow response). I’ll give adding things back in line by line a try. I appreciate the help!