PyRoot: Writing TMultiGraph to root file

I am trying to write a TMultiGraph containing two TGraphs to a root file. I can write each TGraph individually as their own object to the root file and all the points show up. When I use a TBrowser to look at the file, the TMultiGraph does not show any points. Im not sure what I am doing wrong.

Here is my code:

myfile = rt.TFile( f'../../web/static/Runs/{x.run_num}/root/chambers.root', 'RECREATE' )
myfile.mkdir("Lumi_iMon/")
myfile.cd("Lumi_iMon/")

c1 = rt.TCanvas( 'c1', 'Lumi_iMon', 200, 10, 700, 500 )
c1.SetGrid()

x_ML1 = np.array(lumi_ML1,dtype = float)
x_ML2 = np.array(lumi_ML2,dtype = float)
y_ML1 = np.array(iMon_ML1,dtype = float)
y_ML2 = np.array(iMon_ML2, dtype = float)


gr = rt.TGraph(len(x_ML1),x_ML1,y_ML1)
gr1 = rt.TGraph(len(x_ML2), x_ML2, y_ML2)

mg = rt.TMultiGraph()
mg.GetYaxis().SetTitle( 'Chamber HV IMon' )
mg.GetXaxis().SetTitle( 'Instantaneous Luminosity' )
mg.SetName(f"BOL2C09_lumi")

gr.SetTitle("ML1")
gr.SetMarkerStyle(8)
gr.SetMarkerSize(0.7)
gr.SetMarkerColor(2)

gr1.SetTitle("ML2")
gr1.SetMarkerStyle(8)
gr1.SetMarkerSize(0.7)
gr1.SetMarkerColor(4)

mg.Add(gr)
mg.Add(gr1)

mg.Draw( 'AP' )

c1.Update()

mg.Write()

c1.Close()
myfile.Close()

Here are some screenshots of my TBrowser (first picture is TMultiGraph, second is TGraph individually):

Dear @ehazelto ,

This is an adapted Python snippet from the tutorial ROOT: tutorials/graphs/multigraph.C File Reference

import ROOT
import numpy

with ROOT.TFile.Open("multigraph.root", "recreate") as f:
    ROOT.gStyle.SetOptFit()
    c = ROOT.TCanvas("c1", "multigraph", 700, 500)
    c.SetGrid()
    mg = ROOT.TMultiGraph()

    x1 = numpy.array([-0.1, 0.05, 0.25, 0.35, 0.5, 0.61, 0.7, 0.85, 0.89, 0.95], dtype=float)
    y1 = numpy.array([-1, 2.9, 5.6, 7.4, 9, 9.6, 8.7, 6.3, 4.5, 1], dtype=float)
    ex1 = numpy.array([.05, .1, .07, .07, .04, .05, .06, .07, .08, .05], dtype=float)
    ey1 = numpy.array([.8, .7, .6, .5, .4, .4, .5, .6, .7, .8], dtype=float)
    n1 = len(x1)

    gr1 = ROOT.TGraphErrors(n1, x1, y1, ex1, ey1)
    gr1.SetMarkerColor(ROOT.kBlue)
    gr1.SetMarkerStyle(21)
    gr1.Fit("pol6", "q")
    mg.Add(gr1)

    x2 = numpy.array([-0.28, 0.005, 0.19, 0.29, 0.45, 0.56, 0.65, 0.80, 0.90, 1.01], dtype=float)
    y2 = numpy.array([2.1, 3.86, 7, 9, 10, 10.55, 9.64, 7.26, 5.42, 2], dtype=float)
    ex2 = numpy.array([.04, .12, .08, .06, .05, .04, .07, .06, .08, .04], dtype=float)
    ey2 = numpy.array([.6, .8, .7, .4, .3, .3, .4, .5, .6, .7], dtype=float)
    n2 = len(x2)

    gr2 = ROOT.TGraphErrors(n2, x2, y2, ex2, ey2)
    gr2.SetMarkerColor(ROOT.kRed)
    gr2.SetMarkerStyle(20)
    gr2.Fit("pol5", "q")
    mg.Add(gr2)

    mg.Draw("ap")

    c.Update()
    stats1 = gr1.GetListOfFunctions().FindObject("stats")
    stats2 = gr2.GetListOfFunctions().FindObject("stats")

    if (stats1 and stats2):
        stats1.SetTextColor(ROOT.kBlue)
        stats2.SetTextColor(ROOT.kRed)
        stats1.SetX1NDC(0.12)
        stats1.SetX2NDC(0.32)
        stats1.SetY1NDC(0.75)
        stats2.SetX1NDC(0.72)
        stats2.SetX2NDC(0.92)
        stats2.SetY1NDC(0.78)
        c.Modified()


    f.WriteObject(mg, "multigraph")

I see the TMultiGraph object properly when I open the ROOT browser next

I am not sure what could be the difference w.r.t. your snippet. One potential suspect is mg.Write(), I usually go for tfile.WriteObject which I believe better conveys the intention. Maybe you could try using that and see if it fixes the problem?

Cheers,
Vincenzo