Skip to content
Extraits de code Groupes Projets
Valider a515ebb3 rédigé par fbury's avatar fbury
Parcourir les fichiers

Add vertical drawing

parent cee385a7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter