-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
120 lines (95 loc) · 3.64 KB
/
plot.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
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
import matplotlib.pyplot as plt
lab_mem = "内存大小(MB)"
lab_time = "时间(s)"
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
def plot_data_size(data_size: list, run_time: list, mem_size: list, fn: str):
fig, ax1 = plt.subplots()
color1 = 'tab:blue'
ax1.set_xlabel('数据量', fontsize=14)
ax1.set_ylabel(lab_time, color=color1, fontsize=14)
ax1.plot(data_size, run_time, color=color1)
ax1.tick_params(axis='y', labelcolor=color1)
for x in ax1.get_xticklabels(): # 获取x轴上所有坐标,并设置字号
x.set_fontsize(14)
for y in ax1.get_yticklabels():
y.set_fontsize(14)
ax2 = ax1.twinx() # 创建共用x轴的第二个y轴
color2 = 'tab:orange'
ax2.set_ylabel(lab_mem, color=color2, fontsize=14)
ax2.plot(data_size, mem_size, color=color2)
ax2.tick_params(axis='y', labelcolor=color2)
for y in ax2.get_yticklabels():
y.set_fontsize(14)
fig.tight_layout()
plt.savefig(fn)
plt.show()
def plot_rule_length(rls: list, run_time: list, mem_size: list, fn: str):
fig, ax1 = plt.subplots()
color1 = 'tab:blue'
ax1.set_xlabel('规则长度', fontsize=14)
ax1.set_ylabel(lab_time, color=color1, fontsize=14)
ax1.plot(rls, run_time, color=color1)
ax1.tick_params(axis='y', labelcolor=color1)
for x in ax1.get_xticklabels(): # 获取x轴上所有坐标,并设置字号
x.set_fontsize(14)
for y in ax1.get_yticklabels():
y.set_fontsize(14)
ax1.set_ylim([0, 70])
ax2 = ax1.twinx() # 创建共用x轴的第二个y轴
ax2.set_ylim([500, 1600])
# axes = plt.gca()
# axes.set_ylim([30,90])
color2 = 'tab:orange'
ax2.set_ylabel(lab_mem, color=color2, fontsize=14)
ax2.plot(rls, mem_size, color=color2)
ax2.tick_params(axis='y', labelcolor=color2)
for y in ax2.get_yticklabels():
y.set_fontsize(14)
fig.tight_layout()
plt.savefig(fn)
plt.show()
def plot_rule_depth(rds: list, run_time: list, mem_size: list, fn: str):
fig, ax1 = plt.subplots()
color1 = 'tab:blue'
ax1.set_xlabel('规则深度', fontsize=14)
ax1.set_ylabel(lab_time, color=color1, fontsize=14)
ax1.plot(rds, run_time, color=color1)
ax1.tick_params(axis='y', labelcolor=color1)
for x in ax1.get_xticklabels(): # 获取x轴上所有坐标,并设置字号
x.set_fontsize(14)
for y in ax1.get_yticklabels():
y.set_fontsize(14)
ax1.set_ylim([0, 70])
ax2 = ax1.twinx() # 创建共用x轴的第二个y轴
ax2.set_ylim([500, 1600])
# axes = plt.gca()
# axes.set_ylim([30,90])
color2 = 'tab:orange'
ax2.set_ylabel(lab_mem, color=color2, fontsize=14)
ax2.plot(rds, mem_size, color=color2)
ax2.tick_params(axis='y', labelcolor=color2)
for y in ax2.get_yticklabels():
y.set_fontsize(14)
fig.tight_layout()
plt.savefig(fn)
plt.show()
if __name__ == "__main__":
data_size = ["112MB", "224MB", "341MB", "451MB"]
run_time = [24, 40, 69, 90]
mem_size = [792, 1316, 1542, 1593]
# plot_data_size(data_size, run_time, mem_size, "1.png")
# rls = ["2", "3", "4"]
# run_time = [20, 19, 20]
# mem_size = [710, 733, 693]
rls = ["2", "5", "10"]
run_time = [14.511, 14.903, 16.384]
mem_size = [632, 772, 859]
# plot_rule_length(rls, run_time, mem_size, "2.png")
# rds = rls
# run_time = [19, 18, 20]
# mem_size = [746, 653, 698]
rds = ["1", "5", "10"]
run_time = [13.641, 13.901, 15.852]
mem_size = [731, 577, 639]
plot_rule_depth(rds, run_time, mem_size, "3.png")