From d6451f23605b9f2b5939504525ca7deda574bea5 Mon Sep 17 00:00:00 2001 From: fbury <florian.bury@cern.ch> Date: Tue, 26 Oct 2021 10:35:33 +0200 Subject: [PATCH] Added vertical drawing of ex2 --- Chapter_5/Histogram.py | 7 +------ Chapter_5/ex2.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 Chapter_5/ex2.py diff --git a/Chapter_5/Histogram.py b/Chapter_5/Histogram.py index 7a4720c..33589a2 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 0000000..ba81709 --- /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() -- GitLab