1 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS, _lighten; from _utils.vivid_config import palette_colors 2 setup_style(); scale_colors = palette_colors() 3 import matplotlib.pyplot as plt 4 import matplotlib.colors as mcolors 5 import numpy as np 6 7 methods = ['Ours', 'BERT', 'GPT-4', 'LLaMA', 'T5'] 8 metrics = ['Acc', 'F1', 'Prec', 'Rec'] 9 scores = np.array([[0.92, 0.90, 0.91, 0.89], 10 [0.88, 0.86, 0.89, 0.84], 11 [0.90, 0.88, 0.87, 0.90], 12 [0.85, 0.83, 0.86, 0.81], 13 [0.87, 0.85, 0.88, 0.83]]) 14 ci = np.random.uniform(0.01, 0.03, scores.shape) 15 16 # Compute p-values (simulated) for gradient coloring 17 np.random.seed(42) 18 pvals = np.random.uniform(0.001, 0.1, scores.shape) 19 pvals[0, :] = np.random.uniform(0.001, 0.01, 4) # Ours is most significant 20 21 fig, ax = plt.subplots(figsize=(8, 5)) 22 23 # Subtle grid 24 ax.grid(axis='x', alpha=0.15, linestyle='-', color=COLORS['grid']) 25 ax.set_axisbelow(True) 26 27 y_base = np.arange(len(methods)) 28 offsets = np.linspace(-0.25, 0.25, len(metrics)) 29 30 # Gradient colormap for significance 31 cmap_sig = mcolors.LinearSegmentedColormap.from_list('sig', [scale_colors[1], scale_colors[4] if len(scale_colors) > 4 else scale_colors[0], scale_colors[2] if len(scale_colors) > 2 else scale_colors[0]]) 32 33 for j, metric in enumerate(metrics): 34 for i in range(len(methods)): 35 # Color by significance (lower p = greener) 36 sig_norm = min(pvals[i, j] / 0.1, 1.0) 37 dot_color = cmap_sig(1 - sig_norm) 38 ax.errorbar(scores[i, j], y_base[i] + offsets[j], xerr=ci[i, j], 39 fmt='o', color=dot_color, markersize=8, capsize=3, 40 linewidth=1.5, markeredgecolor='white', markeredgewidth=0.8, 41 label=metric if i == 0 else '', zorder=3) 42 43 # Pooled estimate diamond for each method 44 pooled = np.mean(scores, axis=1) 45 pooled_ci = np.mean(ci, axis=1) 46 for i in range(len(methods)): 47 diamond_x = [pooled[i] - pooled_ci[i], pooled[i], pooled[i] + pooled_ci[i], pooled[i]] 48 diamond_y = [y_base[i] + 0.35, y_base[i] + 0.42, y_base[i] + 0.35, y_base[i] + 0.28] 49 ax.fill(diamond_x, diamond_y, color=PALETTE[0] if i == 0 else COLORS['ref_line'], 50 alpha=0.7, zorder=4) 51 ax.text(pooled[i] + pooled_ci[i] + 0.008, y_base[i] + 0.35, 52 f'{pooled[i]:.3f}', fontsize=7, va='center', color=COLORS['text']) 53 54 ax.set_yticks(y_base) 55 ax.set_yticklabels(methods, fontsize=10) 56 ax.set_xlabel('Score', fontsize=11) 57 58 # Custom legend 59 from matplotlib.lines import Line2D 60 legend_elements = [Line2D([0], [0], marker='o', color='w', markerfacecolor=PALETTE[j], 61 markersize=8, label=metrics[j]) for j in range(len(metrics))] 62 legend_elements.append(Line2D([0], [0], marker='D', color='w', markerfacecolor=COLORS['ref_line'], 63 markersize=8, label='Pooled')) 64 ax.legend(handles=legend_elements, loc='lower right', frameon=False, labelspacing=0.35, handlelength=1.6, fontsize=8, ncol=3) 65 ax.invert_yaxis() 66 ax.spines['top'].set_visible(False) 67 ax.spines['right'].set_visible(False) 68 fig.tight_layout() 69 save_fig(fig, 'figures/fig_dot_ci.pdf')