Drawing histogram in a divided canvas pyRoot

Dear Experts,

Please, how can I draw a histogram in all the pads of a divided canvas. I am attaching here a small example to illustrate the issue.

import ROOT
h = ROOT.TH1F('h','h',100,0.,10.)
h.FillRandom("gaus",10000)
can = ROOT.TCanvas("can","multipads",900,700)
ROOT.gPad.SetTickx(2)
can.Divide(3,2,0,0)
for j in range(6):
    can.cd(j+0)
    h.Draw()
can.SaveAs("Plots.png")

This only saves the final Pad as it is shown bellow

Please, How can I fix it ?

can.Divide(3, 2, 1e-11, 1e-11)
for j in range(6):
    can.cd(j + 1)
    h.Draw()
can.cd(0)
can.SaveAs("Plots.png")

Hi Wile,

Unfortunately it didn’t work I get the same plot that I have attached above.

Sara

This one works

import ROOT
h = ROOT.TH1F('h','h',100,0.,10.)
h.FillRandom("gaus",10000)
can = ROOT.TCanvas("can","multipads",900,700)
ROOT.gPad.SetTickx(2)
can.Divide(3,2)
for j in range(6):
    can.cd(j+1)
    h.Draw()
can.SaveAs("Plots.png")

And with 0 margins between the pads also

import ROOT
h = ROOT.TH1F('h','h',100,0.,10.)
h.FillRandom("gaus",10000)
can = ROOT.TCanvas("can","multipads",900,700)
ROOT.gPad.SetTickx(2)
can.Divide(3,2,0,0)
for j in range(6):
    can.cd(j+1)
    h.Draw()
can.SaveAs("Plots.png")

1 Like

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