forked from gzavo/CS_Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
50 lines (35 loc) · 1.31 KB
/
plot.py
File metadata and controls
50 lines (35 loc) · 1.31 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
import csv
import matplotlib.pyplot as plt
import numpy as np
import scipy.optimize as scp
with open("istherecorrelation.csv", "r", encoding='utf-8-sig') as csvfile:
csv_reader = csv.reader(csvfile)
i = 0
values = []
for row in csv_reader:
if i == 0:
titles = row[0].split(';')
print(titles)
else:
values.append(np.array(row[0].split(';'), dtype=float))
i += 1
data = np.array(values)
fig = plt.figure()
fig.suptitle("Correlation between WO and beer consumption in the Netherlands.")
sub1 = fig.add_subplot(111)
sub2 = sub1.twinx()
sub1.scatter(data[:,0], data[:,1], s=15, c='blue')
sub1.plot(data[:,0], data[:,1], c='blue', label='WO')
sub2.scatter(data[:,0], data[:,2], s=15, c='orange')
sub2.plot(data[:,0], data[:,2], c='orange', label='Beer consumption')
sub2.yaxis.tick_right()
sub2.yaxis.set_label_position("right")
sub1.set_xlabel(titles[0])
sub1.set_ylabel(titles[1])
sub2.set_ylabel(titles[2])
# both subplots in one legend
lns, labels = sub1.get_legend_handles_labels()
lns2, labels2 = sub2.get_legend_handles_labels()
sub2.legend(lns + lns2, labels + labels2, loc=0)
plt.savefig("beer.png", format="png", dpi=300, bbox_inches='tight')
plt.show()