File size: 6,029 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 154 155 156 157 158 159 160 161 162 163 | import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
# 数据
labels = [
'ADE847', 'Context459', 'ADE150', 'Context59', 'VOC20', 'VOC21',
'OV-COCO', 'OV-LVIS', 'Obj365', 'COCO',
'Context60', 'COCO-Obj', 'CityScape', 'Context59', 'ADE', 'COCO-Stf'
]
declip = [40, 40, 40, 40, 40, 40,
40, 40, 40, 40,
40, 40, 40, 40, 40, 40]
catseg = [31.37,35.52,35.01,37.98,39.16,38.07,
0, 0, 0, 0,
0, 0, 0, 0, 0, 0]
clipself = [0, 0, 0, 0, 0, 0,
36.68, 33.6, 39.00,39.51,
0, 0, 0, 0, 0, 0]
clearclip = [0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
36.94, 36.26, 36.58, 36.63, 30.50, 37.78]
declip_value = [15.3, 21.4, 36.3, 60.6, 96.6, 81.3,
48.3, 41.5, 20.0, 41.0,
35.3, 36.4, 32.8, 39.2, 21.9, 25.3]
catseg_value = [12.0, 19.0, 31.8, 57.5, 94.6, 77.3,
0, 0, 0, 0,
0, 0, 0, 0, 0, 0]
clipself_value = [0, 0, 0, 0, 0, 0,
44.3, 34.9, 19.5,40.5,
0, 0, 0, 0, 0, 0]
clearclip_value = [0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
32.6, 33.0, 30.0, 35.9, 16.7, 23.9]
# 设置不均匀的角度
# 第一组占90度
group1_angles = np.linspace(0, np.deg2rad(90), 6).tolist() # 0-90度
gap1 = np.deg2rad(50) # 50度的间隔
# 第二组占60度
group2_angles = np.linspace(np.deg2rad(90) + gap1, np.deg2rad(90) + gap1 + np.deg2rad(60), 4).tolist() # 140-200度
gap2 = np.deg2rad(50) # 50度的间隔
# 第三组占90度
group3_angles = np.linspace(np.deg2rad(90) + gap1 + np.deg2rad(60) + gap2, np.deg2rad(90) + gap1 + np.deg2rad(60) + gap2 + np.deg2rad(90), 6).tolist() # 250-340度
# 最后20度与第一组的间隔
angles = group1_angles + group2_angles + group3_angles
angles += angles[:1] # 闭合曲线
# 数据补充,首尾相连
declip = np.concatenate((declip, [declip[0]]))
catseg = np.concatenate((catseg, [catseg[0]]))
clipself = np.concatenate((clipself, [clipself[0]]))
clearclip = np.concatenate((clearclip, [clearclip[0]]))
# 创建图形,调整figsize
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
# 设置雷达图的范围(r轴),最大值为 50
ax.set_ylim(0, 40.5)
# 控制径向环的数量和位置
ax.set_yticks([10, 20, 30, 40]) # 手动设置径向环的值
# 绘制每组数据的区域,增加透明度
ax.fill(angles, declip, color='#3dab5a', alpha=0.15, label='DECLIP', zorder=1)
ax.fill(angles, catseg, color='#ad4fa0', alpha=0.2, label='Previous SOTA CATSeg', zorder=1)
ax.fill(angles, clipself, color='#2b83bc', alpha=0.2, label='Previous SOTA CLIPSelf', zorder=1)
ax.fill(angles, clearclip, color='#db3939', alpha=0.2, label='Previous SOTA ClearCLIP', zorder=1)
# 绘制边框线
ax.plot(angles, declip, color='#52b36a', linewidth=1.5, linestyle='solid', zorder=2)
ax.plot(angles, catseg, color='#ad4fa0', linewidth=1.5, linestyle='solid', zorder=2)
ax.plot(angles, clipself, color='#2b83bc', linewidth=1.5, linestyle='solid', zorder=2)
ax.plot(angles, clearclip, color='#db3939', linewidth=1.5, linestyle='solid', zorder=2)
# 绘制数据点
ax.scatter(angles, declip, facecolors='white', edgecolors='#3dab5a', s=35, zorder=3, linewidth=1.5, alpha=0.9)
ax.scatter(angles, catseg, facecolors='white', edgecolors='#ad4fa0', s=35, zorder=3, linewidth=1.5, alpha=0.9)
ax.scatter(angles, clipself, facecolors='white', edgecolors='#2b83bc', s=35, zorder=3, linewidth=1.5, alpha=0.9)
ax.scatter(angles, clearclip, facecolors='white', edgecolors='#db3939', s=35, zorder=3, linewidth=1.5, alpha=0.9)
# 设置标签
ax.set_xticks(angles[:-1])
ax.set_xticklabels([]) # 不显示标签文字
# 隐藏径向标签
ax.set_yticklabels([])
# 调整参考线为实线,并降低宽度
ax.spines['polar'].set_visible(False)
ax.grid(True, linestyle='-', linewidth=0.5)
# 在每个数据点上标注其对应的值,分别处理不同组的数据位置
for index,(angle, position,value) in enumerate(zip(angles, declip,declip_value)):
if value > 0:
if index<6:
ax.text(angle, position+1, f'{value:.1f}', color='#0b9444', fontsize=12,
ha='left', va='center')
elif index>=6 and index < 10:
ax.text(angle, position+0.5, f'{value:.1f}', color='#0b9444', fontsize=12,
ha='right', va='bottom')
else:
ax.text(angle, position+1.5, f'{value:.1f}', color='#0b9444', fontsize=12,
ha='left', va='top')
for angle, position,value in zip(angles, catseg ,catseg_value):
if value > 0:
ax.text(angle, position-1, f'{value}', color='#92278f', fontsize=12,
ha='right', va='top') # catseg
for angle, position,value in zip(angles, clipself,clipself_value):
if value > 0:
ax.text(angle, position-1, f'{value}', color='#213f9a', fontsize=12,
ha='left', va='top') # clipself
for angle, position,value in zip(angles, clearclip,clearclip_value):
if value > 0:
ax.text(angle, position-1.0, f'{value}', color='#bf1e2d', fontsize=12,
ha='right', va='bottom') # clearclip
# 添加图例
legend_elements = [
Patch(facecolor='#3dab5a', edgecolor='#3dab5a', label='DeCLIP'),
Patch(facecolor='#ad4fa0', edgecolor='#ad4fa0', label='Previous SOTA CATSeg'),
Patch(facecolor='#2b83bc', edgecolor='#2b83bc', label='Previous SOTA CLIPSelf'),
Patch(facecolor='#db3939', edgecolor='#db3939', label='Previous SOTA ClearCLIP'),
]
ax.legend(handles=legend_elements,
frameon=False,
fontsize='large',
loc='center',
bbox_to_anchor=(0.26, 0.99))
# 设置x轴标签背景颜色为不透明
for label in ax.get_xticklabels():
label.set_bbox(dict(facecolor='white', edgecolor='none', alpha=1.0))
# 调整图形布局,增加边距
plt.tight_layout()
# 保存图片
plt.savefig('radar_chart.png', dpi=400, bbox_inches='tight', transparent=True)
# 显示图像
plt.close() |