forked from sailoog/openplotter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
77 lines (65 loc) · 2.41 KB
/
graph.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# This file is part of Openplotter.
# Copyright (C) 2015 by sailoog <https://github.com/sailoog/openplotter>
#
# Openplotter is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# any later version.
# Openplotter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import os, sys, datetime, csv
from matplotlib.widgets import Cursor
pathname = os.path.dirname(sys.argv[0])
currentpath = os.path.abspath(pathname)
ifile = open(currentpath+'/weather_log.csv', "r")
reader = csv.reader(ifile)
log_list = []
for row in reader:
log_list.append(row)
ifile.close()
dates=[]
pressure=[]
temperature=[]
humidity=[]
for i in range(0,len(log_list)):
dates.append(datetime.datetime.fromtimestamp(float(log_list[i][0])))
pressure.append(round(float(log_list[i][1]),1))
temperature.append(round(float(log_list[i][2]),1))
humidity.append(round(float(log_list[i][3]),1))
if len(dates)==0:
dates.append(datetime.datetime.now())
pressure.append(0)
temperature.append(0)
humidity.append(0)
fig=plt.figure()
plt.rc("font", size=10)
fig.canvas.set_window_title('Thermograph / Barograph / Hygrograph')
ax1 = fig.add_subplot(311)
ax2 = fig.add_subplot(312, sharex=ax1)
ax3 = fig.add_subplot(313, sharex=ax1)
ax1.plot(dates,temperature,'ro-')
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%y %H:%M'))
ax1.set_title('Temperature (Cel)')
ax1.grid(True)
ax2.plot(dates,pressure,'go-')
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%y %H:%M'))
ax2.set_title('Pressure (hPa)')
ax2.grid(True)
ax3.plot(dates,humidity,'bo-')
ax3.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%y %H:%M'))
ax3.set_title('Humidity (%)')
ax3.grid(True)
plt.tight_layout()
cursor = Cursor(ax1, useblit=True, color='gray', linewidth=1 )
cursor2 = Cursor(ax2, useblit=True, color='gray', linewidth=1 )
cursor3 = Cursor(ax3, useblit=True, color='gray', linewidth=1 )
fig.autofmt_xdate()
plt.show()