Input-output of a histogram to/from a XML file
Code: "io_example3.py". Programming language: Python DMelt Version 1. Last modified: 03/05/2017. License: Pro
https://datamelt.org/code/cache/io_example3_7484.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 java.util import Random

h1=H1D("test H1D",20,-3,3)
h1.setFill(1)

p0=P0D("test P0D")
r=Random()           # fill with random numbers
for i in range(100):
      h1.fill(2*r.nextGaussian())
      p0.add(r.nextGaussian()+10)
a=[] # put both objects to the list
a.append(h1)
a.append(p0)

IO.writeXML(a,'file.xml')  # write to a XML file
print IO.toXML(a)          # convert to XML string

b=IO.readXML('file.xml')   # read back from XML
print b


Ads help maintain this website.