diff --git a/Chapter_5/Histogram.py b/Chapter_5/Histogram.py index b19810aa7c8d3112dc75717dec0f16a51830b0d3..7a4720c8de513f39d200d3e7db66b475c98f030f 100644 --- a/Chapter_5/Histogram.py +++ b/Chapter_5/Histogram.py @@ -56,6 +56,31 @@ class Histogram: if scale != 1: print ("y-axis scale : 1 # = {}".format(1./scale)) + def drawT(self): + """Affiche l'histogramme en console verticalement (plus facile) """ + # Scale my data (bin content) to a fixed width # + y_max = self.get_maximum() + width = 60 + scale = width/y_max + scaled_data = [b*scale for b in self._data] + # Draw y axis # + print ('-' * width + '> y') + # Draw bin by bin # + for ibin,bin_content in enumerate(scaled_data): + line = f'{ibin:3d}|' + for y in range(width): + if bin_content>= y: + line += "#" + else: + line += " " + # Show the unscaled bin content on the right # + line += f'\t{self._data[ibin]:6.0f}' + print (line) + # Draw end of x axis # + print (' v') + print (' x') + # Print scaling of histogram # + print (f'Scaling : `#` = {scale:.5f}') @@ -67,10 +92,11 @@ if __name__=="__main__": h.fill(0.1) h.fill(2) h.fill(-1) - h.draw() + #h.draw() + h.drawT() - h2 = Histogram(100,-5,5) + h2 = Histogram(50,-5,5) from random import gauss - for i in range(int(100000)): + for i in range(int(1000000)): h2.fill(gauss(0,1)) - h2.draw() + h2.drawT()