Editting Statbox in a divided canvas: follow up for TGraphErrorss

after this post Editting Statbox in a divided canvas, I encouter the same problem here, with Tgrapherrors.

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 …


ROOT Version: 6.26.00 (conda_forge)
Platform: ubuntu20.04
Compiler: gcc9


what does …

`st = gr.FindObject("stats")`

… give you ?

Well, if you see the “stats” box displayed, you could try: st = ROOT.gPad.GetPrimitive("stats")

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.

Before doing the fits, add: ROOT.gStyle.SetOptFit();

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

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