from java.awt import Color
from jhplot import *
from java.util import Random
h1=H1D("test H1D",20,-3,3)
h1.setFill(1)
h1.setFillColor(Color.cyan)
p0=P0D("test P0D")
r=Random()
for i in range(100):
h1.fill(2*r.nextGaussian())
p0.add(r.nextGaussian()+10)
# print all statistics
print p0.getStat()
# put to a list
a=[]
a.append(h1)
a.append(p0)
# write to a XML file
IO.writeXML(a,'file.xml')
# convert to XML string
print IO.toXML(a)
# read back from XML
b=IO.readXML('file.xml')
# print collections
print b
# plot
c1 = HPlot("Canvas",600,400)
c1.setGTitle("P0D and H1D from a serialized XML file");
c1.visible(1)
c1.setAutoRange()
c1.draw(b[0])
# convert first to H1D histogram with 100 bins
c1.draw(b[1].getH1D(100))
# convert to string
# print IO.toXML(a)
Ads help maintain this website.