How to get a merged TMultiGraph Output from a Canvas.SaveAs

Hello experts!

I’m attempting to get an output from using TMultigraph, and I have tried adding a gPad.Update() after every Draw(), as I’ve seen in a few forum answers. I’ve tried leaving out the legend, which sometimes causes problems, and I’ve looked into other forums, but haven’t been lucky enough to fetch an answer. Please help!

outputDir = "combinedplots/"
def plot_all_eff(data_pt, data_eta, labels=['Data', 'Simulation'], xlabel='variable', ylabel='Efficiency'):
    
mg = ROOT.TMultiGraph() # multigraph initialization                                                                                         

#Add all DATA                                                                                                                                   
    for i in range(data_pt):
        data_pt[i].SetLineColor(++i)
        data_pt[i].SetMarkerColor(++i) # sets a different color per input                                                                       
        mg.Add(data_pt[i]) # add by iterating through                                                                                           
    for j in range(data_eta):
        data_eta[j].SetLineColor(++i)
        data_eta[j].SetLineColor(++i)
        mg.Add(data_eta[j])

    canvas = ROOT.TCanvas('c1', 'c1', 800, 800)
    mg.Draw('ALP') # connected line with error bar dots                                                                                         
    gPad.Update() # after each Draw                                                                                                             

    mg.GetXAxis().SetTitle(xlabel)
    mg.GetYAxis().SetTitle(ylabel)
    mg.GetYAxis().SetRangeUser(0.8, 1.10) # efficiency range                                                                                    
    mg.GetXAxis().SetRangeUser(20, 120) # to compare with same range of UL_2018                                                                 

    legend = ROOT.TLegend(0.5, 0.70, 0.92, 0.92)
    legend.SetTextFont(42)
    legend.SetBorderSize(0)
    legend.SetFillColor(0)
    for i in range(data_pt):
        legend.AddEntry(data_pt[i], labels[i], 'l')
    for j in range(data_eta):
        legend.AddEntry(data_eta[j], labels[j], 'l')
    legend.SetHeader("Legend", "C") # center                                                                                                    
    legend.Draw()
    gPad.Update()

                                                                                                  
    canvas.Modified()
    canvas.Update()
    canvas.SaveAs(outputDir + "pleasework.png")

I’m getting the error:

    for i in range(data_pt):
TypeError: 'TGraphAsymmErrors' object cannot be interpreted as an integer

where I’ve defined what I’m hoping to point to as:

for f in file_list_pt:
    #print(f)                                                                                                                                   

    inFile_pt = ROOT.TFile.Open(f, "READ") # open each file to get the object g_0_Data from key class TGraphAsymmErrors                         
    data_pt = inFile_pt.Get("g_0_Data")

where file_list_pt is simply a list of files that correspond to the TGraphAsymmErrors Class.

In your “plot_all_eff” function, the input parameters “data_pt” and “data_eta” are lists of graphs, not individual / single graphs.

Thanks; you can close this session now–we resolved our dilemma.