Writing and reading histograms in/from file
Code: "io_histo_simple.py". Programming language: Python DMelt Version 1.4. Last modified: 12/27/1970. License: Pro
https://datamelt.org/code/cache/io_histo_simple_2096.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


from jhplot import *
from jhplot.io import *
from java.util import Random

h1=H1D('Simple1',20, -2.0, 2.0)
r=Random()
for i in range(1000):
      h1.fill(r.nextGaussian())
hb = HBook("output.jdat","w") # HBook object
hb.write("data",h1)           # write histogram
hb.close()

print "Reading the histogram"
hb = HBook("output.jdat")  # read HBook object
print hb.getKeys()         # print all the keys
h2=hb.get("data")
c1 = HPlot("Canvas")
c1.setGTitle("Histograms from a file");
c1.visible(1)
c1.setAutoRange()
c1.draw(h2)

Ads help maintain this website.