1 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS 2 setup_style() 3 import matplotlib.pyplot as plt 4 import numpy as np 5 6 methods = ['Ours', 'BERT', 'GPT', 'RoBERTa'] 7 datasets = ['MNLI', 'QQP', 'SST-2', 'QNLI'] 8 ranks = [[1, 1, 2, 1], [3, 2, 1, 3], [2, 3, 3, 2], [4, 4, 4, 4]] 9 10 fig, ax = plt.subplots(figsize=(8, 5)) 11 x = np.arange(len(datasets)) 12 13 # Subtle grid 14 ax.grid(axis='y', alpha=0.15, linestyle='-', color=COLORS['grid']) 15 ax.set_axisbelow(True) 16 17 for i, (m, r) in enumerate(zip(methods, ranks)): 18 is_ours = (i == 0) 19 lw = 3.5 if is_ours else 1.8 20 alpha_line = 1.0 if is_ours else 0.55 21 ms = 14 if is_ours else 9 22 23 # Gradient ribbon for "Ours" 24 if is_ours: 25 for k in range(len(x) - 1): 26 x_fill = np.linspace(x[k], x[k + 1], 50) 27 y_fill = np.interp(x_fill, x, r) 28 ax.fill_between(x_fill, y_fill - 0.15, y_fill + 0.15, 29 alpha=0.15, color=PALETTE[0]) 30 31 # Line 32 ax.plot(x, r, 'o-', color=PALETTE[i], linewidth=lw, markersize=ms, 33 label=m, zorder=3 + (1 if is_ours else 0), alpha=alpha_line, 34 markeredgecolor='white', markeredgewidth=1.5 if is_ours else 0.8) 35 36 # Rank labels at both ends 37 ax.text(x[0] - 0.2, r[0], f'#{r[0]} {m}', va='center', ha='right', 38 fontsize=9, color=PALETTE[i], 39 fontweight='bold' if is_ours else 'normal') 40 ax.text(x[-1] + 0.2, r[-1], f'#{r[-1]} {m}', va='center', ha='left', 41 fontsize=9, color=PALETTE[i], 42 fontweight='bold' if is_ours else 'normal') 43 44 # Highlight box for "Ours" 45 ax.annotate('★ Ours: Rank #1 in 3/4 datasets', 46 xy=(x[0], ranks[0][0]), xytext=(x[0] + 0.5, ranks[0][0] - 0.6), 47 fontsize=8.5, color=PALETTE[0], fontweight='bold', 48 arrowprops=dict(arrowstyle='->', color=PALETTE[0], lw=1.2), 49 bbox=dict(boxstyle='round,pad=0.3', facecolor='white', 50 edgecolor=PALETTE[0], alpha=0.9)) 51 52 ax.set_xticks(x) 53 ax.set_xticklabels(datasets, fontsize=10) 54 ax.set_yticks([1, 2, 3, 4]) 55 ax.set_yticklabels(['1st', '2nd', '3rd', '4th'], fontsize=10) 56 ax.set_ylabel('Rank', fontsize=11) 57 ax.invert_yaxis() 58 ax.set_xlim(-0.6, len(datasets) - 0.4) 59 ax.spines['top'].set_visible(False) 60 ax.spines['right'].set_visible(False) 61 fig.tight_layout() 62 save_fig(fig, 'figures/fig_bump.pdf')