File size: 5,084 Bytes
c50dde6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
# =========================
# 数据与预处理
# =========================
labels = [
'MATH-500', 'AIME24', 'AIME25', 'GSM8K', 'AMC23', 'Olympiad',
'MATH-500', 'AIME24', 'AIME25', 'GSM8K', 'AMC23', 'Olympiad',
'MATH-500', 'AIME24', 'AIME25', 'GSM8K', 'AMC23', 'Olympiad',
'MATH-500', 'AIME24', 'AIME25', 'GSM8K', 'AMC23', 'Olympiad',
]
ReBalance_value = [83.0, 36.7, 30.0, 78.3, 80.0, 43.9,
92.6, 56.7, 40.0, 91.6, 95.0, 57.0,
94.0, 73.3, 56.7, 96.3, 100.0, 66.3,
95.2, 70.0, 63.3, 96.8, 95.0, 68.6]
CoD_value = [80.2, 33.3, 13.3, 69.5, 62.5, 35.2,
90.0, 46.7, 36.7, 84.5, 85.0, 47.5,
93.8, 66.7, 53.3, 95.6, 95.0, 62.2,
93.8, 63.3, 46.7, 96.2, 92.5, 67.7]
SEAL_value = [78.6, 23.3, 26.7, 76.4, 53.8, 32.7,
90.6, 43.3, 26.7, 88.4, 77.5, 53.9,
93.4, 63.3, 50.0, 95.7, 90.0, 62.3,
92.6, 63.3, 56.7, 96.2, 95.0, 67.5]
def normalize_values(target, base_values, method_values):
normalized = []
for base, value in zip(base_values, method_values):
if base == 0 or value == 0:
normalized.append(0)
else:
normalized.append((value / base) * target)
return normalized
def enhance_contrast(values, power=2.0, target_max=40):
arr = np.array(values, dtype=float)
arr_scaled = arr ** power
return (arr_scaled / arr_scaled.max()) * target_max
# 数据准备
ReBalance_target = 40
ReBalance = normalize_values(ReBalance_target, ReBalance_value, ReBalance_value)
CoD = normalize_values(ReBalance_target, ReBalance_value, CoD_value)
SEAL = normalize_values(ReBalance_target, ReBalance_value, SEAL_value)
ReBalance = enhance_contrast(ReBalance, power=2.0, target_max=ReBalance_target)
CoD = enhance_contrast(CoD, power=2.0, target_max=ReBalance_target)
SEAL = enhance_contrast(SEAL, power=2.0, target_max=ReBalance_target)
# 设置角度
num_groups = 4
tasks_per_group = 6
gap_deg = 18
group_arc = (360 - num_groups * gap_deg) / num_groups
point_arc = group_arc / tasks_per_group
angles = []
current_angle = 0
for g in range(num_groups):
for t in range(tasks_per_group):
angles.append(np.deg2rad(current_angle))
current_angle += point_arc
current_angle += gap_deg
# 首尾相连
angles += [angles[0]]
ReBalance = np.concatenate((ReBalance, [ReBalance[0]]))
CoD = np.concatenate((CoD, [CoD[0]]))
SEAL = np.concatenate((SEAL, [SEAL[0]]))
# =========================
# 绘图 (CVPR/NIPS 风格)
# =========================
colors = {
"ReBalance": "#00E676", # 荧光绿
"CoD": "#FFB300", # 亮橙黄
"SEAL": "#00B0FF", # 亮青蓝
}
markers = {"ReBalance": "o", "CoD": "s", "SEAL": "D"}
linestyles = {"ReBalance": "-", "CoD": "--", "SEAL": "-."}
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
# 额外绘制半径为40的圆圈
theta = np.linspace(0, 2*np.pi, 500)
ax.plot(theta, np.full_like(theta, 40),
color="black", linewidth=1.2, linestyle="-", zorder=0.5)
ax.set_ylim(0, 44)
# 背景与网格
ax.set_facecolor("white")
ax.grid(True, color="gray", linestyle="--", linewidth=0.6, alpha=0.6)
ax.spines["polar"].set_visible(False)
ax.set_yticks([]) # 移除半径方向的刻度
ax.set_yticklabels([]) # 移除半径方向的刻度标签
# 绘制每个方法
def plot_method(values, angles, label):
# 淡淡背景填充
if label=="ReBalance":
ax.fill(angles, values, color=colors[label], alpha=0.05, zorder=1)
else:
ax.fill(angles, values, color=colors[label], alpha=0.1, zorder=1)
# 折线
ax.plot(angles, values, color=colors[label],
linewidth=2.2, linestyle=linestyles[label],
label=label, zorder=2)
# 数据点
ax.scatter(angles, values,
facecolors="white", edgecolors=colors[label],
linewidths=1.5, marker=markers[label],
s=55, zorder=3)
plot_method(ReBalance, angles, "ReBalance")
plot_method(CoD, angles, "CoD")
plot_method(SEAL, angles, "SEAL")
# =========================
# 在中心画一个灰色实心圆点(带黑色边框)
# =========================
ax.scatter(0, 0,
c="gray", edgecolors="black",
s=120, zorder=5, linewidths=1.0)
# 标签
ax.set_xticks(angles[:-1])
ax.set_xticklabels(labels, fontsize=12, color="black")
for label in ax.get_xticklabels():
label.set_horizontalalignment("center")
# 图例
legend_elements = [
Patch(facecolor=colors["ReBalance"], edgecolor=colors["ReBalance"], label="ReBalance (Ours)"),
Patch(facecolor=colors["CoD"], edgecolor=colors["CoD"], label="CoD"),
Patch(facecolor=colors["SEAL"], edgecolor=colors["SEAL"], label="SEAL"),
]
ax.legend(
handles=legend_elements,
frameon=False,
fontsize=14,
loc="upper center",
bbox_to_anchor=(0.78, 1.12),
)
plt.tight_layout()
plt.savefig("radar_chart_cvpr_with_center.png", dpi=300, transparent=True)
plt.close() |