Skip to content

Commit 43583a2

Browse files
Add files via upload
1 parent 7378181 commit 43583a2

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
if __name__ == '__main__':
20+
bound = [-10.0, 10.0]
21+
fig = plt.figure(figsize=(2.5, 2.5))
22+
ax = fig.add_subplot(1, 1, 1, projection='3d')
23+
x, y, z = generate_xyz(ackley, bound, bound, 1000)
24+
ax.plot_surface(x, y, z, cmap='cool',
25+
rstride=200, cstride=200, alpha=0.9)
26+
ax.set_title('多峰函数', fontsize=10)
27+
ax.set_xlim(bound)
28+
ax.set_ylim(bound)
29+
ax.set_xticks([-10.0, -5.0, 0.0, 5.0, 10.0], fontsize=10)
30+
ax.set_yticks([-10.0, -5.0, 0.0, 5.0, 10.0], fontsize=10)
31+
ax.set_zticks([0.0, 5.0, 10.0], fontsize=10)
32+
ax.set_xlabel('维度1', fontsize=10)
33+
ax.set_ylabel('维度2', fontsize=10)
34+
ax.set_zlabel('适应值', fontsize=10, rotation='vertical')
35+
plt.savefig('3d_ackley.png', dpi=700, bbox_inches='tight')
36+
plt.show()
37+
38+
bound = [-10.0, 10.0]
39+
fig = plt.figure(figsize=(2.5, 2.5))
40+
ax = fig.add_subplot(1, 1, 1, projection='3d')
41+
x, y, z = generate_xyz(griewank, bound, bound, 1000)
42+
ax.plot_surface(x, y, z, cmap='cool',
43+
rstride=100, cstride=100, alpha=0.9)
44+
ax.set_title('多峰函数', fontsize=10)
45+
ax.set_xlim(bound)
46+
ax.set_ylim(bound)
47+
ax.set_xticks([-10.0, -5.0, 0.0, 5.0, 10.0], fontsize=10)
48+
ax.set_yticks([-10.0, -5.0, 0.0, 5.0, 10.0], fontsize=10)
49+
ax.set_zticks([0.0, 1.0, 2.0, 3.0], fontsize=10)
50+
ax.set_xlabel('维度1', fontsize=10)
51+
ax.set_ylabel('维度2', fontsize=10)
52+
ax.set_zlabel('适应值', fontsize=10, rotation='vertical')
53+
plt.savefig('3d_griewank.png', dpi=700, bbox_inches='tight')
54+
plt.show()

0 commit comments

Comments
 (0)