-
Notifications
You must be signed in to change notification settings - Fork 2
/
xvsy
executable file
·40 lines (29 loc) · 843 Bytes
/
xvsy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# Draws a graph of x values vs y values - Getting pairs of x,y lines from standard input
#
# Requires the matplotlib package
#
import os,sys
import pylab
import time
from optparse import OptionParser
from datetime import datetime
from pytz import timezone
def ts_to_datetime(ts):
ts = float(ts) / 1000
tz = timezone('US/Eastern')
return datetime.fromtimestamp(ts,tz)
parser = OptionParser()
parser.add_option("-d","--date",dest="date",default=False,action="store_true",
help="Treat first parameter as time")
(options,args) = parser.parse_args()
if len(args) == 0 or args[0] == '-':
f = sys.stdin
else:
f = file(args[0])
data = [map(float,x.rstrip().split()) for x in f.readlines()]
xs,ys = zip(*data)
if options.date:
xs = map(lambda x:ts_to_datetime(x),xs)
pylab.scatter(xs,ys)
pylab.show()