1 import numpy as np
   2 import matplotlib.pyplot as plt
   3 import matplotlib.colors as mcolors
   4 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS, _lighten
   5 setup_style()
   6 
   7 datasets = ['CIFAR-10', 'CIFAR-100', 'ImageNet', 'STL-10']
   8 methods = ['Ours', 'ViT', 'ResNet', 'DeiT']
   9 scores = np.array([[95.2, 78.3, 82.1, 93.5], [93.1, 75.8, 80.5, 91.2],
  10                     [91.5, 73.2, 79.8, 89.8], [92.8, 76.1, 81.2, 90.5]])
  11 stds = np.random.uniform(0.3, 0.8, scores.shape)
  12 
  13 fig, ax = plt.subplots(figsize=(9, 5))
  14 x = np.arange(len(datasets))
  15 width = 0.18
  16 
  17 # Heatmap-style coloring: normalize scores per dataset
  18 for j in range(len(datasets)):
  19     col_min, col_max = scores[:, j].min() - 2, scores[:, j].max() + 2
  20     cmap = plt.cm.YlGn
  21     norm = plt.Normalize(col_min, col_max)
  22     ranks = np.argsort(np.argsort(-scores[:, j])) + 1  # 1 = best
  23 
  24     for i, method in enumerate(methods):
  25         offset = (i - len(methods) / 2 + 0.5) * width
  26         color = cmap(norm(scores[i, j]))
  27         bar = ax.bar(x[j] + offset, scores[i, j], width, yerr=stds[i, j], capsize=3,
  28                       color=_lighten(color, 0.35), edgecolor=color, linewidth=1.0,
  29                       error_kw={'elinewidth': 0.8, 'capthick': 0.6})
  30 
  31         # Rank number on top
  32         rank = ranks[i]
  33         is_best = rank == 1
  34         ax.text(x[j] + offset, scores[i, j] + stds[i, j] + 0.4,
  35                 f'{"★" if is_best else ""}{scores[i, j]:.1f}',
  36                 ha='center', fontsize=7, fontweight='bold' if is_best else 'normal',
  37                 color=COLORS['down'] if is_best else COLORS['text'])
  38 
  39 # Method legend (manual)
  40 for i, method in enumerate(methods):
  41     ax.bar([], [], color=_lighten(PALETTE[i], 0.4), label=method, edgecolor=PALETTE[i], linewidth=1.2)
  42 
  43 ax.set_xticks(x)
  44 ax.set_xticklabels(datasets, fontsize=10)
  45 ax.set_ylabel('Accuracy (%)', fontsize=11)
  46 ax.legend(frameon=False, labelspacing=0.35, handlelength=1.6, fontsize=9, ncol=len(methods))
  47 ax.set_ylim(68, 100)
  48 ax.spines['top'].set_visible(False)
  49 ax.spines['right'].set_visible(False)
  50 ax.grid(axis='y', alpha=0.15, linestyle='--')
  51 fig.tight_layout()
  52 save_fig(fig, 'figures/fig_dataset_compare.pdf')