1 import numpy as np 2 import matplotlib.pyplot as plt 3 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS, _lighten 4 setup_style() 5 6 x = np.arange(2015, 2025) 7 series = { 8 '本文方法': np.array([72, 75, 78, 80, 83, 85, 87, 89, 91, 92]), 9 '方法B': np.array([70, 73, 76, 79, 81, 82, 84, 86, 88, 89]), 10 '方法C': np.array([68, 70, 72, 75, 77, 79, 80, 82, 83, 84]), 11 } 12 markers = ['o', 's', '^'] 13 stds = {k: np.random.uniform(1.5, 3.0, len(v)) for k, v in series.items()} 14 15 fig, ax = plt.subplots(figsize=(8, 5)) 16 highlight_index = 0 # 重点系列的位置,与显示名称无关 17 18 # 淡色背景渐变 19 ax.axhspan(min(min(v) for v in series.values()) - 5, 20 max(max(v) for v in series.values()) + 5, 21 alpha=0.02, color=PALETTE[0], zorder=0) 22 23 for i, (name, y) in enumerate(series.items()): 24 is_ours = i == highlight_index 25 noise = stds[name] 26 27 # 渐变填充置信带 28 for layer, alpha in enumerate([0.15, 0.08, 0.03]): 29 ax.fill_between(x, y - noise * (1 - layer * 0.2), y + noise * (1 - layer * 0.2), 30 alpha=alpha, color=PALETTE[i], linewidth=0) 31 32 # 主折线 33 ax.plot(x, y, f'{markers[i]}-', color=PALETTE[i], 34 linewidth=2.5 if is_ours else 1.8, markersize=7 if is_ours else 5, 35 markeredgecolor='white', markeredgewidth=1.2, label=name, zorder=3) 36 37 # 极值标注(最大值) 38 max_idx = np.argmax(y) 39 ax.scatter(x[max_idx], y[max_idx], s=120 if is_ours else 80, color=PALETTE[i], 40 edgecolor='white', linewidth=2, zorder=4, marker='*') 41 if is_ours: 42 ax.annotate(f'★ {y[max_idx]:.1f}', 43 xy=(x[max_idx], y[max_idx]), 44 xytext=(x[max_idx] - 1.5, y[max_idx] + 3), 45 fontsize=9, fontweight='bold', color=PALETTE[i], 46 arrowprops=dict(arrowstyle='->', color=PALETTE[i], lw=1.2), 47 bbox=dict(boxstyle='round,pad=0.3', facecolor='white', 48 edgecolor=PALETTE[i], alpha=0.9)) 49 50 ax.set_xlabel('年份', fontsize=11) 51 ax.set_ylabel('准确率 (%)', fontsize=11) 52 ax.legend(frameon=False, labelspacing=0.35, handlelength=1.6, fontsize=9, loc='best') 53 ax.set_xticks(x) 54 ax.grid(alpha=0.12, linestyle='--', color=COLORS['grid']) 55 ax.spines['top'].set_visible(False) 56 ax.spines['right'].set_visible(False) 57 fig.tight_layout() 58 save_fig(fig, 'figures/fig_line.pdf')