Plotting multiple histograms on the same canvas in PyROOT Jupyter notebook

Hello! I’m using ROOT on a Jupyter notebook and I’m having some trouble plotting histograms on the same axes. I only started using ROOT 2 days ago so I’m still very new! I’ve tried two methods:

canv = ROOT.TCanvas(“newcanvas”,“New canvas”,800,600)
hist1.Draw()
hist2.Draw(“same”)
hist3.Draw(“same”)
canv.Draw()

This seems to only plot histograms hist1 and hist2, not hist3

I also tried:

stack = ROOT.THStack(“stack”,“stack”)
stack.Add(hist1)
stack.Add(hist2)
stack.Add(hist3)
canv2 = ROOT.TCanvas(“stackcanvas”,“Stack canvas”,800,400)
stack.Draw()
canv2.Draw()

And this produces a graph which looks nothing like I expect! (presumably I have misunderstood the meaning of THStack or Add). The values that appear on the graph do not match up with those in the histogram.

Any advice would be greatly appreciated!
Thank you :smiley:

Hi!

hist3 not being drawn sounds like a bug! I’ll check who of us can have a look.

For THStack, you did check the doc, right? 'Cause by default the histograms are stacked on top of each other, i.e. the bin values are added. "nostack" just overlays them. Is that the issue?

That sounds like the issue! I’ll check the doc again :smiley: Thank you so much!
EDIT: just had to add "no stack" and it works as expected, thank you again :smiley:

1 Like