DeCLIP-TPAMI / tools /plot_radar_release.py
xiaomoguhzz's picture
Add files using upload-large-folder tool
c50dde6 verified
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
# dataset
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] # scale value
# Data has been desensitized here; you can fill in your own data.
declip_value = [20, 20, 20, 20, 20, 20,
20, 20, 20, 20,
20, 20, 20, 20, 20, 20]
catseg_value = [10, 10, 10, 10, 10, 10,
0, 0, 0, 0,
0, 0, 0, 0, 0, 0]
clipself_value = [0, 0, 0, 0, 0, 0,
10, 10, 10,10,
0, 0, 0, 0, 0, 0]
clearclip_value = [0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
10, 10, 10, 10, 10, 10]
def calc_ratio(base, num, den):
return [base[i] * (num[i] / den[i]) if den[i] != 0 else 0 for i in range(len(base))]
catseg = calc_ratio(declip, catseg_value, declip_value)
clipself = calc_ratio(declip, clipself_value, declip_value)
clearclip = calc_ratio(declip, clearclip_value, declip_value)
# Set non-uniform angles
# The first group occupies 90 degrees
group1_angles = np.linspace(0, np.deg2rad(90), 6).tolist() # 0-90 degrees
gap1 = np.deg2rad(50) # 50 degree gap
# The second group occupies 60 degrees
group2_angles = np.linspace(np.deg2rad(90) + gap1, np.deg2rad(90) + gap1 + np.deg2rad(60), 4).tolist() # 140-200 degrees
gap2 = np.deg2rad(50) # 50 degree gap
# The third group occupies 90 degrees
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 degrees
# The last 20 degrees gap with the first group
angles = group1_angles + group2_angles + group3_angles
angles += angles[:1] # Close the curve
# Data supplement, connect the first and last
declip = np.concatenate((declip, [declip[0]]))
catseg = np.concatenate((catseg, [catseg[0]]))
clipself = np.concatenate((clipself, [clipself[0]]))
clearclip = np.concatenate((clearclip, [clearclip[0]]))
# Create figure, adjust figsize
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
# Set the range of the radar chart (r-axis), max value is 50
ax.set_ylim(0, 40.5)
# Control the number and position of radial rings
ax.set_yticks([10, 20, 30, 40]) # Manually set the values of the radial rings
# Draw the area for each data group, increase transparency
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)
# Draw border lines
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)
# Draw data points
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)
# Set labels
ax.set_xticks(angles[:-1])
ax.set_xticklabels([]) # Do not show label text
# Hide radial labels
ax.set_yticklabels([])
# Adjust reference lines to solid and reduce width
ax.spines['polar'].set_visible(False)
ax.grid(True, linestyle='-', linewidth=0.5)
# Annotate each data point with its corresponding value, handle different group positions separately
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
# Add legend
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))
# Set x-axis label background to opaque
for label in ax.get_xticklabels():
label.set_bbox(dict(facecolor='white', edgecolor='none', alpha=1.0))
# Adjust figure layout, increase margin
plt.tight_layout()
# Save image
plt.savefig('radar_chart.png', dpi=400, bbox_inches='tight', transparent=True)
# Show image
plt.close()