Convert canvas into histogram in pyroot

Dear Users,

I use PYROOT and I have a TFile with a canvas inside. I need to convert it into an histogram because I will work with it after. I have used some of the topics very related to that but it does not work, maybe because I am using PYROOT.

Hi @mendoza,
sorry for the late reply. What have you tried and what’s the error?
Can you share the TFile with us?

The way to extract a TH1 object (i.e. a histogram) from a canvas in a file is to first extract the canvas from the file and then extract the histogram from the canvas:

f = ROOT.TFile("file.root")
c = f.Get("canvasname")
histo = c.GetPrimitive("histoname")


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