diff --git a/bashplotlib/histogram.py b/bashplotlib/histogram.py index fe0a5f7..3775e0b 100644 --- a/bashplotlib/histogram.py +++ b/bashplotlib/histogram.py @@ -159,7 +159,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def nlen = max(len(str(min_y)), len(str(max_y))) + 1 if title: - print(box_text(title, max(len(hist) * 2, len(title)), nlen)) + print(box_text([title], max(len(hist) * 2, len(title)), nlen)) print() used_labs = set() @@ -202,17 +202,15 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def center += 15 if showSummary: - print() - print("-" * (2 + center)) - print("|" + "Summary".center(center) + "|") - print("-" * (2 + center)) - summary = "|" + ("observations: %d" % n).center(center) + "|\n" - summary += "|" + ("min value: %f" % min_val).center(center) + "|\n" - summary += "|" + ("mean : %f" % mean).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) + summary_lines = [ + "## Summary ##".center(center), + ("observations: %d" % n).center(center), + ("mean : %f" % mean).center(center), + ("std dev : %f" % sd).center(center), + ("max value: %f" % max_val).center(center), + ("min value: %f" % min_val).center(center), + ] + print(box_text(summary_lines, center)) def main(): diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index 69cab9d..31d22c5 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -32,7 +32,7 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs): plotted = set() if title: - print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1))) + print(box_text([title], 2 * (len(get_scale(xs, False, size)) + 1))) print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) for y in get_scale(ys, True, size): diff --git a/bashplotlib/utils/helpers.py b/bashplotlib/utils/helpers.py index cf209ee..a3b5dd3 100644 --- a/bashplotlib/utils/helpers.py +++ b/bashplotlib/utils/helpers.py @@ -76,11 +76,12 @@ def abbreviate(labels, rfill=' '): return abbrev -def box_text(text, width, offset=0): +def box_text(lines, width, offset=0): """ Return text inside an ascii textbox """ box = " " * offset + "-" * (width+2) + "\n" - box += " " * offset + "|" + text.center(width) + "|" + "\n" + for line in lines: + box += " " * offset + "|" + line.center(width) + "|" + "\n" box += " " * offset + "-" * (width+2) return box