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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bashplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
print(" " * (nlen + 1) + "-" * len(xs))

if xlab:
xlen = len(str(float((max_y) / height) + max_y))
labels = abbreviate([str(b) for b in bins])
xlen = len(labels[0])
for i in range(0, xlen):
printcolour(" " * (nlen + 1), True, colour)
for x in range(0, len(hist)):
num = str(bins[x])
num = labels[x]
if x % 2 != 0:
pass
elif i < len(num):
Expand Down
12 changes: 12 additions & 0 deletions bashplotlib/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ def drange(start, stop, step=1.0, include_stop=False):
r = round(r, 10)


def abbreviate(labels, rfill=' '):
"""
Abbreviate labels without introducing ambiguities.
"""
max_len = max(len(l) for l in labels)
for i in range(1, max_len):
abbrev = [l[:i].ljust(i, rfill) for l in labels]
if len(abbrev) == len(set(abbrev)):
break
return abbrev


def box_text(text, width, offset=0):
"""
Return text inside an ascii textbox
Expand Down
3 changes: 3 additions & 0 deletions examples/sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ hist --file "${dir}/data/exp.txt" --colour blue
echo 'changing the shape of the point'
hist --file "${dir}/data/exp.txt" --pch .

echo 'adding x-labels'
hist --file "${dir}/data/exp.txt" --pch . --xlab

#echo 'using stdin'
#curl -sL https://dl.dropbox.com/u/49171662/example.txt | hist

Expand Down