Write and read histograms using HBook
Code: "io_hbook.py". Programming language: Python DMelt Version 1. Last modified: 12/11/2015. License: Pro
https://datamelt.org/code/cache/io_hbook_6094.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 java.awt import Color
from java.awt import Font
from jhplot  import *
from jhplot.io import *

# create HBook object
hb = HBook("data.jdat","w")

p1=P1D("test")
p1.add(1.0,2.0)
p1.add(2.0,3.0)
hb.write("data",p1) 


h1=H1D("My histogram",100,0,50)
hb.write(20,h1) 

#h2=H2D("My 2D histogram",10,0,50,20,10,20)
#hb.add(22,h2) 

f1=F1D("x*cos(x*10)")
hb.write(1,f1) 

hb.close()

#print hb.getKeys()

# now we read it
hb = HBook("data.jdat")
print hb.getKeys()

"""
hb.read("text.xml")
p1=hb.get("data")
f1=hb.get('1')
print p1.toString()
print f1.toString()

c1=HPlot("Test")
c1.setAutoRange()
c1.draw(p1)
c1.draw(f1)
"""

Ads help maintain this website.