Skip to content

Commit 27e28cc

Browse files
committed
add standard deviation to histogram summary
1 parent 51b05e6 commit 27e28cc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

‎bashplotlib/histogram.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
109109
f=open(f).readlines()
110110

111111
min_val, max_val=None, None
112-
n, mean=0.0, 0.0
112+
n, mean, sd=0.0,0.0, 0.0
113113

114114
fornumberinread_numbers(f):
115115
n+=1
@@ -121,6 +121,12 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
121121

122122
mean/=n
123123

124+
fornumberinread_numbers(f):
125+
sd+= (mean-number)**2
126+
127+
sd/= (n-1)
128+
sd**=0.5
129+
124130
bins=list(calc_bins(n, min_val, max_val, bincount, binwidth))
125131
hist=dict((i, 0) foriinrange(len(bins)))
126132

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

0 commit comments

Comments
(0)