-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcategoryvsy
executable file
·59 lines (43 loc) · 1.18 KB
/
categoryvsy
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/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
import numpy as np
import matplotlib.pyplot as plt
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")
parser.add_option("-t","--title",dest="title",default="",
help="Set title")
(options,args) = parser.parse_args()
if len(args) == 0 or args[0] == '-':
f = sys.stdin
else:
f = file(args[0])
data = [x.rstrip().split() for x in f.readlines()]
xs,ys = zip(*data)
ys = map(float,ys)
if options.date:
xs = map(lambda x:ts_to_datetime(x),xs)
ind = np.arange(len(xs))
width = 1
fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(ind,ys,width,color='r')
ax.set_ylabel('y')
ax.set_title(options.title)
ax.set_xticks(ind + width)
ax.set_xticklabels( xs)
fig.autofmt_xdate()
plt.show()