+#!/usr/bin/env python3
+
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import sys
import common
-
+# Mainloop
def main():
+
+ # Matplotlib setup
matplotlib.use('AGG')
plt.figure()
+
try:
csv_file_path = sys.argv[1]
except IndexError:
raise ValueError("Need csv file argument")
+
+
d1 = common.load_csv(csv_file_path)
x, y = prepare_data(d1)
draw_diagram1(x, y)
+
plt.ylabel("Cups of coffee")
plt.xlabel("Time of day")
plt.savefig("uppgift_1.png")
- return
+# Format the data into relevant axis
def prepare_data(data):
new_list = []
x_values = []
for rader in data:
new_list.append(rader.split(";"))
+ # Ignore day tag
new_list = new_list[1:]
+ # Convert data from str to int
for i, rad in enumerate(new_list):
for j, s in enumerate(rad):
new_list[i][j] = int(s.strip())
- # [int(s.strip()) for rad in new_list[1:] for s in rad]
+ # Sum up y values
for rad in new_list:
x_values.append(rad[0])
y_values.append(sum(rad[1:]))
+
return (x_values, y_values)
+# Uses data as arguments and draws it onto axis
def draw_diagram1(x_values, y_values):
plt.plot(x_values, y_values)
-
if __name__ == "__main__":
main()