Repository navigation
Expand file tree
/
Copy pathplot.py
More file actions
129 lines (111 loc) · 3.2 KB
/
Copy pathplot.py
File metadata and controls
129 lines (111 loc) · 3.2 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import pandas as pd
import numpy as np
# convert to dataframe
data = {
'variant': ['1', '2', '3', '4', '5'],
'electronic_recall@20': [0.56976, 0.8371, 0.77143, 0.75929, 0.755],
'electronic_ndcg@20': [0.37138, 0.5373, 0.49057, 0.48268, 0.47319],
'food_recall@20': [0.5824, 0.8459, 0.79692, 0.79272, 0.78688],
'food_ndcg@20': [0.37982, 0.5242, 0.49393, 0.48005, 0.4813]
}
df = pd.DataFrame(data)
# COLOR PLOT
RED = '#E63946'
GRAY = '#36454F'
# plot linebetween
std1 = np.array([0.001, 0.0008, 0.0007, 0.0009, 0.0006]) * 15
std2 = np.array([0.0005, 0.009, 0.0007, 0.0008, 0.0009]) * 10
std1_ndcg = np.array([0.002, 0.0018, 0.0007, 0.0009, 0.0012]) * 10
# fontproperties for plot
bold_font = FontProperties(weight='bold')
# plot
fig, ax = plt.subplots(1, 2, figsize=(8, 3))
# Recall@20
ax[0].plot(
df['variant'],
df['electronic_recall@20'],
marker='o',
label='Electronic',
color='#E63946',
linestyle='-.'
)
ax[0].plot(
df['variant'],
df['food_recall@20'],
marker='^',
label='Food',
linestyle='dashed'
)
ax[0].fill_between(
df['variant'],
df['electronic_recall@20'] - std1,
df['electronic_recall@20'] + std1,
alpha=0.2
)
ax[0].fill_between(
df['variant'],
df['food_recall@20'] - std1,
df['food_recall@20'] + std1,
alpha=0.2
)
# ax[0].set_title('Recall@20')
ax[0].set_xlabel('Number of GAT layers $N$', fontweight='bold')
ax[0].set_ylabel('R@20', fontweight='bold', color=GRAY, fontsize=10)
# using fontproperties to make bold text
ax[0].legend(prop=bold_font)
ax[0].grid(axis='y', alpha=0.4)
ax[0].tick_params(axis='y', labelcolor=GRAY)
# NDCG@20
ax[1].plot(
df['variant'],
df['electronic_ndcg@20'],
marker='o',
label='Electronic',
color=RED,
linestyle='-.',
)
ax[1].plot(
df['variant'],
df['food_ndcg@20'],
marker='^',
label='Food',
linestyle='dashed',
)
ax[1].fill_between(
df['variant'],
df['electronic_ndcg@20'] - std1_ndcg,
df['electronic_ndcg@20'] + std1_ndcg,
alpha=0.2,
color=RED
)
# ax[1].fill_between(
# df['variant'],
# df['food_ndcg@20'] - std1,
# df['food_ndcg@20'] + std1,
# alpha=0.2,
# color=RED
# )
# ax[1].set_title('NDCG@20')
ax[1].set_xlabel('Number of GAT layers $N$', fontweight='bold')
ax[1].set_ylabel('N@20', fontweight='bold', color=GRAY, fontsize=10)
# using fontproperties to make bold text
ax[1].legend(prop=bold_font, fancybox=True)
ax[1].grid(axis='y', alpha=0.4)
# make color for y axis
ax[1].tick_params(axis='y', labelcolor=GRAY)
# make value in y-axis and x-axis to bold
for label in ax[0].get_yticklabels():
label.set_fontweight('bold')
for label in ax[1].get_yticklabels():
label.set_fontweight('bold')
for label in ax[0].get_xticklabels():
label.set_fontweight('bold')
for label in ax[1].get_xticklabels():
label.set_fontweight('bold')
# increase distance between 2 figures
plt.subplots_adjust(wspace=0.4)
plt.savefig(f'plot.pdf', dpi=300, bbox_inches='tight')
plt.tight_layout()
plt.show()