-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
48 lines (36 loc) · 1.32 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
__author__ = 'Arran'
import matplotlib.pyplot as plt
from collections import Counter
from parse import Parse
class Graph:
def visualise_days(self):
"""Visualise data by day of the week."""
data_parse = Parse()
data_file = data_parse.main()
# Returns a dict where it sums the total values for each key.
# In this case, the keys are the DaysOfWeek, and the values are
# a count of incidents.
counter = Counter(item["DayOfWeek"] for item in data_file)
# Separate out the counter to order it correctly when plotting.
data_list = [counter["Monday"],
counter["Tuesday"],
counter["Wednesday"],
counter["Thursday"],
counter["Friday"],
counter["Saturday"],
counter["Sunday"]
]
day_tuple = tuple(["Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"])
# Assign the data to a plot
plt.plot(data_list)
# Assign labels to the plot
plt.xticks(range(len(day_tuple)), day_tuple)
# Save the plot!
plt.savefig("Days.png")
# Close figure
plt.clf()
def main(self):
self.visualise_days()
if __name__ == "__main__":
Graph = Graph()
Graph.main()