Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions bashplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion bashplotlib/scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions bashplotlib/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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