import matplotlib.pyplot as plt import numpy as np # 数据 categories = ['DINO/8', 'DINO/16', 'SAM-B', 'SAM-L', 'DINOv2-B', 'DINOv2-L'] x = np.arange(len(categories)) - 0.2 OV_COCO = [42.0, 41.8, 42.6, 42.5, 43.3, 43.3] avg_iou = [40.3, 41.4, 37.9, 40.4, 44.1, 42.9] width = 0.35 fig, ax = plt.subplots(figsize=(8, 4)) bars1 = ax.bar(x - width/2, OV_COCO, width, label='mAP (Novel)', color='#1f77b4', edgecolor='white', hatch='X') bars2 = ax.bar(x + width/2, avg_iou, width, label='Avg. mIoU', color='#ff7f0e', edgecolor='white', hatch='X') ax.set_xticks(x) ax.set_xticklabels(categories, fontsize=13, ha='center') # 调小一号 ax.legend(fontsize=14, loc='upper center', bbox_to_anchor=(0.35, 1.09), ncol=2, frameon=False, handletextpad=0.5, columnspacing=1.0) highlight_fontsize = 12.5 # 调小一号 # 在柱状图上添加数值,并标注最大值 for bar, value in zip(bars1, OV_COCO): if value == max(OV_COCO): ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height(), f'{value:.1f}', ha='center', va='bottom', fontsize=highlight_fontsize, color='red', fontweight='bold') else: ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height(), f'{value:.1f}', ha='center', va='bottom', fontsize=12) # 调小一号 for bar, value in zip(bars2, avg_iou): if value == max(avg_iou): ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height(), f'{value:.1f}', ha='center', va='bottom', fontsize=highlight_fontsize, color='red', fontweight='bold') else: ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height(), f'{value:.1f}', ha='center', va='bottom', fontsize=12) # 调小一号 ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) plt.tick_params(axis='y', labelsize=12) # y轴刻度不变 plt.tight_layout() plt.savefig('vfm_ablation.png', dpi=300)