Write and read a collection of histograms to/from a serialized file
Source code name: "io_histo.py"
Programming language: Python
Topic: File IO/Binary
DMelt Version 1. Last modified: 12/11/2015. License: Pro
https://datamelt.org/code/cache/io_histo_1315.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,Font
from jhplot  import *
from jhplot.io import *
from java.util import Random



# define dictionary
hold = {}

h1=H1D('Simple1',20, -2.0, 2.0)
h1.setFill(1)
h1.setFillColor(Color.green)

h11=H1D('Simple2',20, -2.0, 2.0)
h11.setFill(0)

# fill histograms
r=Random()
for i in range(1000):
      h1.fill(r.nextGaussian())
      h11.fill(r.nextGaussian()+1)


hold["describe"] = "Collection of histograms"
hold["h1"]=h1
hold["h11"]=h11

# write to a file in the user macros directory
IO.write(hold,'file.jser')
 
import time
time.sleep(1)

# deserialize dictionary from the file
hold=IO.read('file.jser' )

# print all keys
print hold.keys()

print "Description: "+hold["describe"]
c1 = HPlot("Canvas",600,400)
c1.setGTitle("Histograms from a serialized file");
c1.visible(1)
c1.setAutoRange()
c1.draw(hold["h1"])
c1.draw(hold["h11"])


You see the box below because you did not login.