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")