-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathc6.py
65 lines (51 loc) · 1.89 KB
/
c6.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
import matplotlib.pyplot as plt
import csv
import numpy as np
import math
x = []
y_stars_f1 = []
y_text_round_f1 = []
y_mean_round_f1 = []
i = 0
with open('result3-blog.csv') as myfile:
reader = csv.DictReader(myfile, delimiter=',')
for line in reader:
i += 1
x.append(i)
y_stars_f1.append(float(line['f1-user-rating']))
y_text_round_f1.append(float(line['f1-review-rating']))
y_mean_round_f1.append(float(line['f1-combined-rating']))
max_value = max([max(y_stars_f1), max(y_mean_round_f1), max(y_text_round_f1)])
fig = plt.figure()
ax = fig.add_subplot(111)
## the data (can be the number of rows in csv file)
N = 3
## necessary variables
ind = np.arange(N) # the x locations for the groups
width = 0.25 # the width of the bars
## the bars
rects1 = ax.bar(ind, y_stars_f1, width,
color='lightblue',
hatch="//"
)
rects2 = ax.bar(ind+width, y_text_round_f1, width,
color='lightgreen',
hatch="-"
)
rects3 = ax.bar(ind+width+width, y_mean_round_f1, width,
color='lightgrey',
hatch="x"
)
# axes and labels
ax.set_xlim(-width,len(ind)+width+(width/2))
ax.set_ylim(0,max_value+0.1)
ax.set_ylabel('F1 measure')
ax.set_title('F1 Measure', color="black", weight="bold", size="large")
xTickMarks = ['Dataset '+str(i) for i in range(1,6)]
ax.set_xticks(ind+width+(width/2))
xtickNames = ax.set_xticklabels(xTickMarks)
plt.setp(xtickNames, rotation=0)
## add a legend
ax.legend( (rects1[0], rects2[0], rects3[0]), ('User ratings', 'Review ratings', 'Combined ratings'), loc='upper right', fancybox=True, shadow=True )
#ax.grid()
plt.show()