1 import numpy as np
   2 import matplotlib.pyplot as plt
   3 from matplotlib.patches import Arc
   4 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS, _lighten, smart_labels
   5 setup_style()
   6 
   7 # === Example data (replace with your model evaluation results) ===
   8 # Reference (observed) statistics
   9 ref_std = 1.0  # normalized
  10 
  11 # Model results: (correlation, normalized_std)
  12 models = {
  13     'Ours':        (0.95, 1.02),
  14     'LSTM':        (0.88, 0.85),
  15     'XGBoost':     (0.91, 1.15),
  16     'SVR':         (0.82, 0.78),
  17     'Linear Reg':  (0.75, 1.30),
  18 }
  19 
  20 fig, ax = plt.subplots(figsize=(7, 7))
  21 
  22 # Draw reference arcs (constant correlation lines)
  23 max_std = 1.6
  24 for corr in [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.99]:
  25     theta = np.arccos(corr)
  26     r_vals = np.linspace(0, max_std, 100)
  27     x_arc = r_vals * np.cos(theta)
  28     y_arc = r_vals * np.sin(theta)
  29     ax.plot(x_arc, y_arc, color=COLORS['grid'], linewidth=0.5, alpha=0.6)
  30     ax.text(max_std * np.cos(theta) * 1.03, max_std * np.sin(theta) * 1.03,
  31             f'{corr}', fontsize=7, color=COLORS['ref_line'], ha='center', va='center',
  32             rotation=np.degrees(theta) - 90)
  33 
  34 # Draw std arcs (centered at origin)
  35 for s in [0.25, 0.5, 0.75, 1.0, 1.25, 1.5]:
  36     theta_range = np.linspace(0, np.pi / 2, 100)
  37     ax.plot(s * np.cos(theta_range), s * np.sin(theta_range),
  38             color=COLORS['grid'], linewidth=0.5, linestyle='--')
  39 
  40 # Draw RMSE arcs (centered at reference point) —— 暖橙色
  41 ref_x, ref_y = ref_std, 0
  42 for rmse in [0.25, 0.5, 0.75, 1.0, 1.25]:
  43     theta_range = np.linspace(0, np.pi, 200)
  44     cx = ref_x + rmse * np.cos(theta_range)
  45     cy = rmse * np.sin(theta_range)
  46     mask = (cx >= 0) & (cy >= 0) & (np.sqrt(cx**2 + cy**2) <= max_std)
  47     if mask.any():
  48         ax.plot(cx[mask], cy[mask], color=COLORS['highlight'], linewidth=0.5,
  49                 alpha=0.4, linestyle=':')
  50 
  51 # Reference point
  52 ax.scatter(ref_std, 0, s=150, color=COLORS['text'], marker='*', zorder=10, label='Observed')
  53 
  54 # ── 绘制模型点:浅色填充+原色边框 标记
  55 label_xs, label_ys, label_texts, label_colors = [], [], [], []
  56 for i, (name, (corr, std)) in enumerate(models.items()):
  57     theta = np.arccos(corr)
  58     x = std * np.cos(theta)
  59     y = std * np.sin(theta)
  60     color = PALETTE[i % len(PALETTE)]
  61     marker = 'D' if i == 0 else 'o'
  62     size = 140 if i == 0 else 90
  63     # 浅色填充 + 原色边框
  64     ax.scatter(x, y, s=size, color=_lighten(color, 0.35), marker=marker, zorder=5,
  65                edgecolors=color, linewidths=1.8, label=name)
  66     label_xs.append(x); label_ys.append(y)
  67     label_texts.append(name); label_colors.append(color)
  68 
  69 # Smart labels to avoid overlap
  70 smart_labels(ax, label_xs, label_ys, label_texts, colors=label_colors,
  71              fontsize=8.5, fontweight='bold', offset=(8, 5))
  72 
  73 ax.set_xlim(0, max_std)
  74 ax.set_ylim(0, max_std)
  75 ax.set_aspect('equal')
  76 ax.set_xlabel('标准差(归一化)', fontsize=11)
  77 ax.set_ylabel('标准差(归一化)', fontsize=11)
  78 ax.spines['top'].set_visible(False)
  79 ax.spines['right'].set_visible(False)
  80 ax.legend(loc='upper left', fontsize=9, frameon=False, edgecolor=COLORS['grid'])
  81 fig.tight_layout()
  82 save_fig(fig, 'figures/fig_taylor.pdf')