Skip to content

Commit 7378181

Browse files
Add files via upload
1 parent 6fa440e commit 7378181

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""This script has been used in Qiqi Duan's Ph.D. Dissertation (HIT&SUSTech).
2+
3+
Chinese: 该绘图脚本被段琦琦的博士论文(哈工大与南科大联合培养)所使用。
4+
"""
5+
import matplotlib
6+
import matplotlib.pyplot as plt
7+
8+
from pypop7.benchmarks.utils import generate_xyz
9+
from pypop7.benchmarks.base_functions import ackley
10+
from pypop7.benchmarks.base_functions import griewank
11+
12+
13+
matplotlib.rcParams['font.family'] = 'sans-serif'
14+
matplotlib.rcParams['font.sans-serif'] = 'SimSun'
15+
matplotlib.rcParams['axes.unicode_minus'] = False
16+
matplotlib.rcParams['font.size'] = 10 # 对应5号字体
17+
18+
19+
# helper function for 2D-plotting
20+
def plot_contour(func, x, y):
21+
x, y, z = generate_xyz(func, x, y, 500)
22+
plt.contourf(x, y, z, cmap='cool')
23+
plt.contour(x, y, z, colors='white', alpha=0.5)
24+
25+
26+
if __name__ == '__main__':
27+
ndim_problem = 2
28+
bound=[-10.0, 10.0]
29+
plt.figure(figsize=(2.5, 2.5))
30+
plt.title('多峰函数', fontsize=10)
31+
plt.xlim(bound)
32+
plt.ylim(bound)
33+
plt.xticks(fontsize=10)
34+
plt.yticks(fontsize=10)
35+
plot_contour(ackley, bound, bound)
36+
plt.xlabel('维度1', fontsize=10)
37+
plt.ylabel('维度2', fontsize=10, labelpad=-1)
38+
plt.savefig(str(ackley.__name__) + '.png', dpi=700, bbox_inches='tight')
39+
plt.show()
40+
41+
ndim_problem = 2
42+
bound=[-10.0, 10.0]
43+
plt.figure(figsize=(2.5, 2.5))
44+
plt.title('多峰函数', fontsize=10)
45+
plt.xlim(bound)
46+
plt.ylim(bound)
47+
plt.xticks(fontsize=10)
48+
plt.yticks(fontsize=10)
49+
plot_contour(griewank, bound, bound)
50+
plt.xlabel('维度1', fontsize=10)
51+
plt.ylabel('维度2', fontsize=10, labelpad=-1)
52+
plt.savefig(str(griewank.__name__) + '.png', dpi=700, bbox_inches='tight')
53+
plt.show()

0 commit comments

Comments
 (0)