Skip to content

Adding option --delimiter #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions bashplotlib/scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs):
print(" |")
print("-" * (2 * len(get_scale(xs, False, size)) + 2))

def plot_scatter(f, xs, ys, size, pch, colour, title):
def plot_scatter(f, xs, ys, size, pch, colour, title, delimiter=','):
"""
Form a complex number.

Expand All @@ -66,9 +66,9 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
if f:
if isinstance(f, str):
with open(f) as fh:
data = [tuple(line.strip().split(',')) for line in fh]
data = [tuple(line.strip().split(delimiter)) for line in fh]
else:
data = [tuple(line.strip().split(',')) for line in f]
data = [tuple(line.strip().split(delimiter)) for line in f]
xs = [float(i[0]) for i in data]
ys = [float(i[1]) for i in data]
if len(data[0]) > 2:
Expand All @@ -90,6 +90,7 @@ def main():
parser = optparse.OptionParser(usage=scatter['usage'])

parser.add_option('-f', '--file', help='a csv w/ x and y coordinates', default=None, dest='f')
parser.add_option('-d', '--delimiter', help='delimiter between x & y values in input file', default=',')
parser.add_option('-t', '--title', help='title for the chart', default="", dest='t')
parser.add_option('-x', help='x coordinates', default=None, dest='x')
parser.add_option('-y', help='y coordinates', default=None, dest='y')
Expand All @@ -104,7 +105,7 @@ def main():
opts.f = sys.stdin.readlines()

if opts.f or (opts.x and opts.y):
plot_scatter(opts.f, opts.x, opts.y, opts.size, opts.pch, opts.colour, opts.t)
plot_scatter(opts.f, opts.x, opts.y, opts.size, opts.pch, opts.colour, opts.t, opts.delimiter)
else:
print("nothing to plot!")

Expand Down