Histogram wont stay open

Very basic question

I’m just starting out learning ROOT.
I’m trying to make a basic histogram and go from there.

This is what I have. Just some generic numbers.

import ROOT
c1=ROOT.TCanvas()

h1 = ROOT.TH1F(“h1”, “h1 title”, 7, 0, 100)

h1.Fill(42)
h1.Fill(42)
h1.Fill(4)
h1.Fill(17)
h1.Fill(7)
h1.Fill(17)
h1.Fill(7)

h1.SetLineColor(2)
h1.Draw(“E1”)

h1.Draw()

When I run it, I can see the histogram for like a half second then the window closes again.
I can make changes and see the changes being made to the graph but it doesn’t stay open.
I don’t get any error messages.
What am I missing?

Hi,

what is happening is that the program ends and all the memory is redeemed, including the one associated to the graphics primitives. This is why this is “flashed” to then disappear.
My suggestion is to do something rather standard. Just add a “raw_input(“Please press enter to continue.”)” at the end of the Python script to allow you to inspect the canvas and exit the program only upon key pressing.

Cheers,
Danilo