-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_same_control.py
139 lines (96 loc) · 4.55 KB
/
draw_same_control.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import matplotlib.pyplot as plt
import string
import numpy as np
from matplotlib.font_manager import FontProperties
CN_font = FontProperties(fname='C:\Windows\Fonts\simsun.ttc', size=7) # 中文字体
EN_font = FontProperties(fname='C:\Windows\Fonts\euclid.ttf', size=7) # 英文字体
plt.rcParams['figure.figsize'] = (5.57, 2.36220471*3/4) # 设置图片大小(单位:英寸)
plt.rcParams['savefig.dpi'] = 600 #设置图片分辨率,600像素/英寸
plt.rcParams['xtick.direction'] = 'in' # 设置x轴tick向内
plt.rcParams['ytick.direction'] = 'in'
makersize = 2 # 线的图标大小
line_width = 0.5
data_1 = []
data_2 = []
data_3 = []
plt.subplot(121) # 子图1
f = open("paper_1/same_control_cost.txt", "r", encoding="utf-8")
lines = f.readlines()
for i in range(0, lines.__len__()):
for j in lines[i].split():
data_1.append(float(j.strip(string.whitespace)))
f.close()
f = open("paper_2/same_control_cost.txt", "r", encoding="utf-8")
lines = f.readlines()
for i in range(0, lines.__len__()):
for j in lines[i].split():
data_2.append(float(j.strip(string.whitespace)))
f.close()
f = open("paper_4/same_control_cost.txt", "r", encoding="utf-8")
lines = f.readlines()
for i in range(0, lines.__len__()):
for j in lines[i].split():
data_3.append(float(j.strip(string.whitespace)))
f.close()
x = [i*0.01 for i in range(len(data_2))]
plt.plot(x, data_1, '-+', label='算法一', color="b", linewidth=line_width, markersize=makersize+2)
plt.plot(x, data_2, '-s', label='算法二', linewidth=1, color="g", markersize=makersize)
plt.plot(x, data_3, '-o', label='算法三', color="y", linewidth=line_width, markersize=makersize)
plt.legend(prop=CN_font, frameon=False, loc='best')
# 修改坐标轴宽度
ax = plt.gca() # gca = 'get current axis' 获取当前坐标
ax.spines['top'].set_linewidth(line_width)
ax.spines['bottom'].set_linewidth(line_width)
ax.spines['left'].set_linewidth(line_width)
ax.spines['right'].set_linewidth(line_width)
ax.set_xticks([0.00, 0.02, 0.04, 0.06, 0.08, 0.10]) # 若横坐标轴刻度显示不完全时,可用这句话重新设置坐标值
plt.xlabel("光纤百公里故障概率", fontproperties=CN_font)
plt.ylabel("故障出现概率", fontproperties=CN_font)
plt.xticks(fontproperties=EN_font) # 设置坐标轴字体
plt.yticks(fontproperties=EN_font)
plt.title("(a) 三种算法在COST239中的可靠性比较", y=-0.42, fontproperties=CN_font) # 加入标题
plt.subplot(122)
data_1 = []
data_2 = []
data_3 = []
f = open("paper_1/same_control_nsf.txt", "r", encoding="utf-8")
lines = f.readlines()
for i in range(0, lines.__len__()):
for j in lines[i].split():
data_1.append(float(j.strip(string.whitespace)))
f.close()
f = open("paper_2/same_control_nsf.txt", "r", encoding="utf-8")
lines = f.readlines()
for i in range(0, lines.__len__()):
for j in lines[i].split():
data_2.append(float(j.strip(string.whitespace)))
f.close()
f = open("paper_4/same_control_nsf.txt", "r", encoding="utf-8")
lines = f.readlines()
for i in range(0, lines.__len__()):
for j in lines[i].split():
data_3.append(float(j.strip(string.whitespace)))
f.close()
x = [i*0.01 for i in range(len(data_2))]
plt.plot(x, data_1, '-+', label='算法一', color="b", linewidth=line_width, markersize=makersize+2)
plt.plot(x, data_2, '-s', label='算法二', linewidth=line_width, color="g", markersize=makersize)
plt.plot(x, data_3, '-o', label='算法三', color="y", linewidth=line_width, markersize=makersize)
plt.legend(prop=CN_font, frameon=False, loc='best')
# 修改坐标轴宽度
ax = plt.gca() # gca = 'get current axis' 获取当前坐标
ax.spines['top'].set_linewidth(line_width)
ax.spines['bottom'].set_linewidth(line_width)
ax.spines['left'].set_linewidth(line_width)
ax.spines['right'].set_linewidth(line_width)
ax.set_xticks([0.00, 0.02, 0.04, 0.06, 0.08, 0.10]) # 若横坐标轴刻度显示不完全时,可用这句话重新设置坐标值
plt.xlabel("光纤百公里故障概率", fontproperties=CN_font)
plt.ylabel("故障出现概率", fontproperties=CN_font)
plt.xticks(fontproperties=EN_font) # 设置坐标轴字体
plt.yticks(fontproperties=EN_font)
plt.title("(b) 三种算法在NSF中的可靠性比较", y=-0.42, fontproperties=CN_font) # 加入标题
# 图间设置
plt.subplots_adjust(wspace=0.4) # 调整子图间距
# 保存图片
plt.savefig('paper_pic/same_control.jpg', format='jpg', bbox_inches='tight', pad_inches=0) # 紧凑型保存
plt.savefig('paper_pic/same_control.svg', format='svg', bbox_inches='tight', pad_inches=0) # 保存成矢量图,方便修改
# plt.show()