From 27e28ccaef49089a0cd3e586674ee74c8439a75d Mon Sep 17 00:00:00 2001 From: Sam Boysel Date: Mon, 4 Jan 2016 11:31:00 -0800 Subject: [PATCH 1/2] add standard deviation to histogram summary --- bashplotlib/histogram.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bashplotlib/histogram.py b/bashplotlib/histogram.py index 4c1ad57..07ab187 100644 --- a/bashplotlib/histogram.py +++ b/bashplotlib/histogram.py @@ -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 @@ -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))) @@ -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) From cf58ab649938f9cbf34bffd5e3cb6744fb68c3c5 Mon Sep 17 00:00:00 2001 From: Sam Boysel Date: Mon, 18 Jan 2016 22:45:40 -0800 Subject: [PATCH 2/2] relabel sd => std dev --- bashplotlib/histogram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bashplotlib/histogram.py b/bashplotlib/histogram.py index 07ab187..43b7dd3 100644 --- a/bashplotlib/histogram.py +++ b/bashplotlib/histogram.py @@ -206,7 +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 += "|" + ("std dev : %f" % sd).center(center) + "|\n" summary += "|" + ("max value: %f" % max_val).center(center) + "|\n" summary += "-" * (2 + center) print(summary)