now i am reading those graphs from a tifile, fit them and put into python array.
then i draw them separately. I cant access the “stats” (it’s a null pointer),
as in the following codes:
file.Open()
graphs = []
for i in range(24):
# gr = file.Get(...)
# gr.SomeFormatting
# gr.Fit()
graphs.append(gr)
c = ROOT.TCanvas("c","c",3600,2400)
c.Divide(6,4)
for i,gr in enumerate(graphs):
sub = c.cd(i+1)
gr.Draw()
print(r.gPad)
gr.Fit(func,"REMQ")
ROOT.gPad.Modified()
ROOT.gPad.Update()
# ROOT.gPad.Modified()
st = gr.FindObject("stats")
st.SetX1NDC(0.6)
st.SetX2NDC(0.9)
st.SetY1NDC(0.7)
st.SetY2NDC(0.9)
ROOT.gPad.Modified()
ROOT.gPad.Update()
c.Draw()
even i did the plot in one single canvas, like this one:
c = ROOT.TCanvas("c","c",3600,2400)
gr=graphs[0]
gr.Draw()
ROOT.gPad.Update()
st = gr.FindObject("stats")
st.SetX1NDC(0.6)
st.SetX2NDC(0.9)
st.SetY1NDC(0.7)
st.SetY2NDC(0.9)
c.Draw()
I tried with different combinations of gPad.Update(), gPad.Modified(), and i havent succeded so far …
the code first throw AttributeError: 'TObject' object has no attribute 'SetX1NDC'
then i checked with gr.FindObject("stats"),gr.GetListOfFunctions().FindObject("stats"), and both of them gave <cppyy.gbl.TObject object at 0x(nil)>
no statbox has been drawn, unless i draw them in the first place and do the editting in another draw.
tried with a single canvas.
it seems like the TGraphErrors does not own the stat box (instead it is own by the canvas). what i found is that the r.gPad.Update(); r.gPad.Modified() did not work regardless you put before and after the get statbox action.
and i seem only can modify the statbox after c.Draw
the following code explains this
ROOT.gStyle.SetOptFit(1111)
c = ROOT.TCanvas("c","c",3600,2400)
gr = file.Get("graph_1")
gr.Draw()
gr.Fit(func,"REMQ")
ROOT.gPad.Update()
ROOT.gPad.Modified()
# st = gr.FindObject("stats") # tgraphs's seem not owning the statbox, it's the canvas that own it
# c.Draw() # worked
st = ROOT.gPad.GetPrimitive("stats")
st.SetX1NDC(0.5)
st.SetX2NDC(0.8)
st.SetY1NDC(0.5)
st.SetY2NDC(0.8)
c.Draw() # not working