Skip to content
Prev Previous commit
Next Next commit
add standard deviation to histogram summary
  • Loading branch information
sboysel committed Jan 4, 2016
commit 27e28ccaef49089a0cd3e586674ee74c8439a75d
9 changes: 8 additions & 1 deletion bashplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
f = open(f).readlines()

min_val, max_val = None, None
n, mean = 0.0, 0.0
n, mean, sd = 0.0, 0.0, 0.0

for number in read_numbers(f):
n += 1
Expand All @@ -121,6 +121,12 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def

mean /= n

for number in read_numbers(f):
sd += (mean - number)**2

sd /= (n - 1)
sd **= 0.5

bins = list(calc_bins(n, min_val, max_val, bincount, binwidth))
hist = dict((i, 0) for i in range(len(bins)))

Expand Down Expand Up @@ -200,6 +206,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
summary = "|" + ("observations: %d" % n).center(center) + "|\n"
summary += "|" + ("min value: %f" % min_val).center(center) + "|\n"
summary += "|" + ("mean : %f" % mean).center(center) + "|\n"
summary += "|" + ("sd : %f" % sd).center(center) + "|\n"
summary += "|" + ("max value: %f" % max_val).center(center) + "|\n"
summary += "-" * (2 + center)
print(summary)
Expand Down