diff --git a/Chapter_5/Histogram.py b/Chapter_5/Histogram.py index 7a4720c8de513f39d200d3e7db66b475c98f030f..33589a27a19d743399afb1225d9a264b67355ecd 100644 --- a/Chapter_5/Histogram.py +++ b/Chapter_5/Histogram.py @@ -67,7 +67,7 @@ class Histogram: print ('-' * width + '> y') # Draw bin by bin # for ibin,bin_content in enumerate(scaled_data): - line = f'{ibin:3d}|' + line = f'{ibin+1:3d}|' for y in range(width): if bin_content>= y: line += "#" @@ -95,8 +95,3 @@ if __name__=="__main__": #h.draw() h.drawT() - h2 = Histogram(50,-5,5) - from random import gauss - for i in range(int(1000000)): - h2.fill(gauss(0,1)) - h2.drawT() diff --git a/Chapter_5/ex2.py b/Chapter_5/ex2.py new file mode 100644 index 0000000000000000000000000000000000000000..ba81709e29a3ab1a3fe94e136d3fb35114ade7c4 --- /dev/null +++ b/Chapter_5/ex2.py @@ -0,0 +1,16 @@ +import random +from Histogram import Histogram + +N = 100000 +# Dice throw # +h1 = Histogram(6,1,7) +for i in range(N): + h1.fill(random.randint(1,6)) +h1.drawT() + +# Gaussian # +h2 = Histogram(50,-5,5) +from random import gauss +for i in range(int(N)): + h2.fill(gauss(0,1)) +h2.drawT()