-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
executable file
·70 lines (61 loc) · 2.11 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 9 12:00:53 2019
@author: pi
"""
import gc
import matplotlib.pyplot as plt
import csv_recording
from matplotlib.dates import DateFormatter
class GraphDrawer:
def __init__(self):
self.point_shape = "."
self.formatter = DateFormatter('%d/%m/%Y\n%H:%M')
# Point shape options
# "." = point
# "," = pixel
# "o" = circle
# "^" = triangle_up
# "v" = triangle_down
# "8" = octagon
# "s" = square
# "p" = pentagon
# "*" = star
# "h" = hexagon
# "+" = plus
# "D" = diamond
def draw_light_level_graph(self, name="data.csv", show=False):
CSV_handler = csv_recording.CSVRecording(name)
plant_data = CSV_handler.read_data(2)
fig = plt.figure(figsize=(14, 5))
plt.plot(plant_data[0], plant_data[1], c='b',
marker=self.point_shape) # linewidth = 0
plt.xlabel('Time', fontsize=16)
plt.ylabel('Light', fontsize=16)
plt.title('scatter plot - Light vs Time', fontsize=20)
plt.gcf().axes[0].xaxis.set_major_formatter(self.formatter)
plt.grid(True)
plt.savefig("LightGraph.png", dpi=300)
if show:
plt.show()
plt.close(fig)
gc.collect()
def draw_moisture_level_graph(self, name="data.csv", show=False):
CSV_handler = csv_recording.CSVRecording(name)
plant_data = CSV_handler.read_data(1)
fig = plt.figure(figsize=(14, 5))
plt.plot(plant_data[0], plant_data[1], c='r', marker=self.point_shape)
plt.xlabel('Time', fontsize=16)
plt.ylabel('Moisture Level', fontsize=16)
plt.title('scatter plot - Moisture Level vs Time', fontsize=20)
plt.gcf().axes[0].xaxis.set_major_formatter(self.formatter)
plt.grid(True)
plt.savefig("MoistureGraph.png", dpi=300)
if show:
plt.show()
plt.close(fig)
gc.collect()
#Graph = GraphDrawer()
# Graph.draw_light_level_graph("fake_data.csv")
# Graph.draw_moisture_level_graph("fake_data.csv")