diff --git a/bashplotlib/histogram.py b/bashplotlib/histogram.py index bfff5b1..3e4d638 100644 --- a/bashplotlib/histogram.py +++ b/bashplotlib/histogram.py @@ -10,7 +10,8 @@ import math import optparse from os.path import dirname -from .utils.helpers import * +from .utils.helpers import (isiterable, drange, box_text, + printcolour, colour_help) from .utils.commandhelp import hist @@ -52,10 +53,11 @@ def run_demo(): if not os.path.isfile(demo_file): sys.stderr.write("demo input file not found!\n") - sys.stderr.write("run the downloaddata.sh script in the example first\n") + sys.stderr.write("run the downloaddata.sh script \ +in the example first\n") sys.exit(1) - #plotting a histogram + # plotting a histogram print "plotting a basic histogram" print "plot_hist('%s')" % demo_file print "hist -f %s" % demo_file @@ -63,28 +65,30 @@ def run_demo(): plot_hist(demo_file) print "*" * 80 - #with colours + # with colours print "histogram with colours" print "plot_hist('%s', colour='blue')" % demo_file print "hist -f %s -c blue" % demo_file plot_hist(demo_file, colour='blue') print "*" * 80 - #changing the shape of the point + # changing the shape of the point print "changing the shape of the bars" print "plot_hist('%s', pch='.')" % demo_file print "hist -f %s -p ." % demo_file plot_hist(demo_file, pch='.') print "*" * 80 - #changing the size of the plot + # changing the size of the plot print "changing the size of the plot" print "plot_hist('%s', height=35.0, bincount=40)" % demo_file print "hist -f %s -s 35.0 -b 40" % demo_file plot_hist(demo_file, height=35.0, bincount=40) -def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="default", title="", xlab=None, showSummary=False, regular=False): +def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", + colour="default", title="", xlab=None, showSummary=False, + regular=False): """ Make a histogram @@ -228,7 +232,8 @@ def main(): if opts.demo: run_demo() elif opts.f: - plot_hist(opts.f, opts.h, opts.b, opts.binwidth, opts.p, opts.colour, opts.t, opts.x, opts.showSummary, opts.regular) + plot_hist(opts.f, opts.h, opts.b, opts.binwidth, opts.p, opts.colour, + opts.t, opts.x, opts.showSummary, opts.regular) else: print "nothing to plot!" diff --git a/bashplotlib/utils/helpers.py b/bashplotlib/utils/helpers.py index bfffe46..bb11c94 100644 --- a/bashplotlib/utils/helpers.py +++ b/bashplotlib/utils/helpers.py @@ -7,7 +7,8 @@ import sys -isiterable = lambda x: hasattr(x, '__iter__') or hasattr(x, '__getitem__') +def isiterable(x): + return hasattr(x, '__iter__') or hasattr(x, '__getitem__') bcolours = { "white": '\033[97m', @@ -68,7 +69,7 @@ def box_text(text, width, offset=0): """ Return text inside an ascii textbox """ - box = " " * offset + "-" * (width+2) + "\n" + box = " " * offset + "-" * (width + 2) + "\n" box += " " * offset + "|" + text.center(width) + "|" + "\n" - box += " " * offset + "-" * (width+2) + box += " " * offset + "-" * (width + 2) return box