-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
executable file
·66 lines (48 loc) · 1.81 KB
/
graph.py
File metadata and controls
executable file
·66 lines (48 loc) · 1.81 KB
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
58
59
60
61
62
63
64
#!/usr/bin/python2.7
#coding=utf-8
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
import datetime
import th_data
import sys
def create_img(ts, values, save_file=None):
dates = map(datetime.datetime.fromtimestamp, ts)
#c = '\xe2\x84\x83' #.encode(encoding='UTF-8')
c="(c) "
last_time = ("Temperature [Last: "+str(values[-1])+c+dates[-1].strftime("%a %d-%m-%Y %H:%M:%S")+"]")
fig, ax = plt.subplots()
ax.plot_date(dates, values, linestyle='dashed',markersize=2, linewidth = 1)
ax.xaxis.set_major_formatter( DateFormatter('%d.%m %H:%M') )
# setting x and y axis range
ax.set_xlim(dates[0], dates[-1])
ax.set_ylim(-1, 35)
# The hour locator takes the hour or sequence of hours you want to
# tick, not the base multiple
#ax.xaxis.set_major_locator(DayLocator())
#ax.xaxis.set_minor_locator(HourLocator(arange(0, 25, 6)))
#ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
# naming the x axis
plt.xlabel('date')
# naming the y axis
plt.ylabel('T(C)')
# giving a title to my graph
plt.title(last_time)
# function to show the plot
if save_file is None:
plt.show()
else:
plt.savefig(save_file)
plt.close(fig)
def do_graph(period, save_file=None):
term_data = th_data.th_data()
(ts, values) = term_data.get_data(period)
create_img(ts, values, save_file)
if __name__ == "__main__":
p = 60
save_file = None
if len(sys.argv) == 2:
p = int(sys.argv[1])
elif len(sys.argv) == 3:
save_file = sys.argv[2]
do_graph(p, save_file)