1 import numpy as np, matplotlib.pyplot as plt
   2 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS
   3 setup_style()
   4 np.random.seed(42)
   5 
   6 # 生成三目标 Pareto 前沿
   7 n = 200
   8 t1 = np.random.uniform(0, 1, n)
   9 t2 = np.random.uniform(0, 1-t1, n)
  10 f1 = t1 + 0.05*np.random.randn(n)
  11 f2 = t2 + 0.05*np.random.randn(n)
  12 f3 = 1 - t1 - t2 + 0.05*np.random.randn(n)
  13 f1, f2, f3 = np.clip(f1, 0, 1), np.clip(f2, 0, 1), np.clip(f3, 0, 1)
  14 
  15 # 非 Pareto 解
  16 other_f1 = np.random.uniform(0.2, 1.0, 100)
  17 other_f2 = np.random.uniform(0.2, 1.0, 100)
  18 other_f3 = np.random.uniform(0.2, 1.0, 100)
  19 
  20 fig = plt.figure(figsize=(8, 6))
  21 ax = fig.add_subplot(111, projection='3d')
  22 # 非支配解
  23 ax.scatter(other_f1, other_f2, other_f3, s=8, alpha=0.15, color=COLORS['neutral'])
  24 # Pareto 前沿
  25 sc = ax.scatter(f1, f2, f3, c=f3, cmap='coolwarm', s=25, alpha=0.7,
  26                 edgecolor='white', linewidth=0.3, zorder=3)
  27 
  28 ax.set_xlabel('目标 f₁', fontsize=10, labelpad=6)
  29 ax.set_ylabel('目标 f₂', fontsize=10, labelpad=6)
  30 ax.set_zlabel('目标 f₃', fontsize=10, labelpad=8)
  31 ax.view_init(elev=25, azim=135); ax.tick_params(labelsize=8)
  32 ax.legend(fontsize=9, loc='best')
  33 fig.colorbar(sc, shrink=0.5, aspect=15, pad=0.1, label='f₃ 值')
  34 fig.tight_layout()
  35 save_fig(fig, 'figures/fig_pareto_3d.pdf')