import matplotlib.pyplot as plt import matplotlib.patches as mpatches import matplotlib.lines as mlines import numpy as np # ── 1. ĐỒNG BỘ SỐ LIỆU CHÍNH XÁC THEO BÁO CÁO ─────────────────────────────── data = [ # Prior work dict(name='Mnist (2015)', mae=7.29, gflops=0.10, params=1.82, group='prior'), dict(name='iTracker (2016)', mae=7.67, gflops=3.97, params=6.28, group='prior'), dict(name='GazeNet (2017)', mae=6.62, gflops=72.24, params=90.23, group='prior'), dict(name='FullFace (2017)', mae=5.65, gflops=29.90, params=190.00, group='prior'), dict(name='RT-Gene (2018)', mae=5.36, gflops=12.21, params=31.66, group='prior'), dict(name='DilatedNet (2019)', mae=5.07, gflops=202.00, params=3.92, group='prior'), # Recent SOTA dict(name='Gaze360 (2019)', mae=4.66, gflops=3.65, params=11.72, group='recent'), dict(name='FAR-Net (2021)', mae=5.12, gflops=0.65, params=1.94, group='recent'), dict(name='FR-Net (2024)', mae=4.95, gflops=0.15, params=0.85, group='recent'), dict(name='FGI-Net (2025)', mae=4.81, gflops=0.08, params=0.45, group='recent'), # Heavy Teacher dict(name='Heavy Teacher (ResNet50)', mae=4.15, gflops=4.12, params=25.56, group='teacher'), # Ours (LIPE V2) dict(name='LIPE V2 (Ours)', mae=4.72, gflops=0.02125, params=0.18, group='ours'), ] # ── 2. CẤU HÌNH STYLE HỌC THUẬT (Muted Earthy Palette) ────────────────────── plt.rcParams['font.family'] = 'sans-serif' plt.rcParams['xtick.direction'] = 'in' plt.rcParams['ytick.direction'] = 'in' GROUP_STYLE = { 'prior': {'color': '#B4B2A9', 'edgecolor': '#5F5E5A', 'label': 'Prior Works (2015-2019)'}, 'recent': {'color': '#6B8E23', 'edgecolor': '#4B6B1D', 'label': 'Recent Edge SOTA'}, 'teacher': {'color': '#A9A9A9', 'edgecolor': '#696969', 'label': 'Heavy Teacher Baseline'}, 'ours': {'color': '#D32F2F', 'edgecolor': '#7B1FA2', 'label': 'LIPE V2 (Ours)'} } fig, ax = plt.subplots(figsize=(7, 5), dpi=300) def bubble_area(p): return 80 + 350 * np.log10(p + 1) # ── 3. VẼ CÁC ĐIỂM DỮ LIỆU VỚI MARKER ĐẶC BIỆT CHO "OURS" ────────────────── for d in data: style = GROUP_STYLE[d['group']] scale_s = bubble_area(d['params']) marker = 'D' if d['group'] == 'ours' else 'o' lw = 1.8 if d['group'] == 'ours' else 0.8 zorder = 5 if d['group'] == 'ours' else 3 ax.scatter( d['gflops'], d['mae'], s=scale_s, color=style['color'], edgecolors=style['edgecolor'], marker=marker, alpha=0.85, linewidths=lw, zorder=zorder ) # ── 4. PHÂN BỔ CÁC ĐIỂM CHỮ (ANNOTATE OFFSET POINT) KHÔNG ĐÈ NHAU ────────── for d in data: is_ours = (d['group'] == 'ours') fw = 'bold' if is_ours else 'normal' col = '#D32F2F' if is_ours else '#424242' fs = 8.5 if is_ours else 7.5 xytext = (8, 0) ha, va = 'left', 'center' if d['name'] == 'LIPE V2 (Ours)': xytext = (-10, 10) ha, va = 'right', 'bottom' elif d['name'] == 'FGI-Net (2025)': xytext = (10, -10) ha, va = 'left', 'top' elif d['name'] == 'FR-Net (2024)': xytext = (10, 8) ha, va = 'left', 'bottom' elif d['name'] == 'FAR-Net (2021)': xytext = (-10, -8) ha, va = 'right', 'top' elif d['name'] == 'Gaze360 (2019)': xytext = (12, 0) ha, va = 'left', 'center' elif d['name'] == 'DilatedNet (2019)': xytext = (-10, 0) ha, va = 'right', 'center' ax.annotate( d['name'], xy=(d['gflops'], d['mae']), xytext=xytext, textcoords="offset points", fontsize=fs, fontweight=fw, color=col, ha=ha, va=va, zorder=6 ) # ── 5. ĐƯỜNG PARETO FRONTIER THEO LOGIC CẠNH BIÊN TỐI ƯU ──────────────────── pareto_x = [0.02125, 0.08, 3.65, 4.12] pareto_y = [4.72, 4.81, 4.66, 4.15] ax.plot(pareto_x, pareto_y, color='#757575', linestyle='--', linewidth=1.2, zorder=2) # ── 6. CẤU HÌNH HỆ TRỤC TỌA ĐỘ VÀ BOUNDARY PADDING ────────────────────────── ax.set_xscale('log') ax.set_xlabel('Computational Complexity (GFLOPs) [Log Scale]', fontsize=9.5, fontweight='bold', labelpad=6) ax.set_ylabel('Gaze Estimation Error (MAE in Degrees) [Lower is Better]', fontsize=9.5, fontweight='bold', labelpad=6) ax.set_xlim(0.0075, 350.0) ax.set_ylim(8.0, 3.8) ax.grid(True, which="both", ls=":", color='#E5E5E5', zorder=1) ax.tick_params(axis='both', colors='#5F5E5A', labelsize=8.5) for spine in ax.spines.values(): spine.set_edgecolor('#D3D1C7') spine.set_linewidth(0.8) # ── 7. BỐ TRÍ LEGEND ĐỒNG BỘ VÀ NÂNG CẤP THẨM MỸ KHUNG SIZE ───────────────── # Hộp 1: Classification (Góc dưới bên trái) group_handles = [] for g in ['ours', 'recent', 'teacher', 'prior']: style = GROUP_STYLE[g] marker = 'D' if g == 'ours' else 'o' group_handles.append(mlines.Line2D( [], [], color='none', marker=marker, markersize=6.5, markerfacecolor=style['color'], markeredgecolor=style['edgecolor'], markeredgewidth=1.0, label=style['label'] )) group_handles.append(mlines.Line2D([], [], color='#757575', linestyle='--', linewidth=1.2, label='Current Pareto Frontier')) legend_group = ax.legend( handles=group_handles, loc='lower left', title='Model Classification', fontsize=8, title_fontsize=8.5, frameon=True, facecolor='white', edgecolor='#D3D1C7', framealpha=0.9 ) ax.add_artist(legend_group) # Hộp 2: Bubble Size (Góc dưới bên phải) - ĐÃ ĐIỀU CHỈNH THU NHỎ SIZE VÀ TĂNG KHOẢNG CÁCH KHUNG sizes = [0.18, 1.94, 11.72, 190.0] size_labels = ['0.18M (Ours)', '1.94M', '11.72M', '190.0M'] # FIX CHÍNH: Nhân 0.45 để thu nhỏ riêng đường kính bong bóng mẫu trong khung Legend size_handles = [ plt.scatter([], [], s=bubble_area(sz) * 0.45, color='#B4B2A9', alpha=0.6, edgecolors='#5F5E5A', marker='o') for sz in sizes ] legend_size = ax.legend( handles=size_handles, labels=size_labels, loc='lower right', title='Bubble Size (Params)', fontsize=8, title_fontsize=8.5, frameon=True, facecolor='white', edgecolor='#D3D1C7', framealpha=0.9, labelspacing=1.1, # Tăng khoảng cách dòng giữa các mục để khung legend rộng rãi hơn borderpad=0.8, # Tăng khoảng đệm từ rìa khung vào các bong bóng bên trong handletextpad=1.0 # Tăng khoảng cách từ bong bóng đến chữ nhãn mô tả ) plt.tight_layout() plt.savefig('Figure_1_Final_Resized.png', dpi=300) plt.show()