Skip to content

Commit 8f7e0a8

Browse files
committed
updated to work w/ stdin
1 parent 1833a43 commit 8f7e0a8

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

bin/hist.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@ def plot_hist(f, height=20, bincount=None, pch="o", colour="white", title=""):
117117
(opts, args) = parser.parse_args()
118118

119119
if opts.f is None:
120-
opts.f = args[0]
121-
120+
if len(args) > 0:
121+
opts.f = args[0]
122+
else:
123+
opts.f = sys.stdin.readlines()
124+
122125
if opts.f:
123126
plot_hist(opts.f, opts.h, opts.b, opts.p, opts.colour, opts.t)
124127
else:

bin/scatter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import csv
33
import optparse
44
from utils.helpers import *
5+
import sys
56

67

78
def get_scale(series, is_y=False, steps=20):
@@ -19,7 +20,10 @@ def get_scale(series, is_y=False, steps=20):
1920

2021
def plot_scatter(f, xs, ys, size, pch, colour, title):
2122
if f:
22-
data = [tuple(map(float, line)) for line in csv.reader(open(f))]
23+
if isinstance(f, str):
24+
f = open(f)
25+
26+
data = [tuple(map(float, line.strip().split(','))) for line in f]
2327
xs = [i[0] for i in data]
2428
ys = [i[1] for i in data]
2529
else:
@@ -73,6 +77,9 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
7377

7478
(opts, args) = parser.parse_args()
7579

80+
if opts.f is None and (opts.x is None or opts.y is None):
81+
opts.f = sys.stdin.readlines()
82+
7683
if opts.f or (opts.x and opts.y):
7784
plot_scatter(opts.f, opts.x, opts.y, opts.size, opts.pch, opts.colour, opts.t)
7885
else:

bin/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import sys
2+
data = sys.stdin.readlines()
3+
print "Counted", len(data), "lines."

0 commit comments

Comments
 (0)