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
| import matplotlib.pyplot as plt import numpy as np def plot_radar_chart(labels, array, title):
plt.rcParams.update({'font.size': 25}) # 设置全局刻度字体大小 # plt.rcParams['xtick.labelsize'] = 25 # x轴刻度字体大小 plt.rcParams['ytick.labelsize'] = 25 # y轴刻度字体大小 fuzzer = ["LLM_atr1","LLM_atr2","LLM_atr3","human"] fuzzer = ["LLM","Human"] colors = ['r','b','r','b'] num_vars = len(labels) len_val = len(array)
angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()
angles += angles[:1] fig, ax = plt.subplots(figsize=(14, 12), subplot_kw=dict(polar=True)) # 设置背景颜色 ax.set_facecolor('#f3f7ff') # 这里设置为浅灰色,你可以根据需要修改颜色
for i in range(len_val): values = [] values = array[i] values += values[:1] # print(angles) # print(values) ax.fill(angles, values, color=colors[i], alpha=0.1) ax.plot(angles, values, linewidth=1, linestyle='solid', label=fuzzer[i])
ax.grid(linewidth=1, linestyle='--', alpha=0.5)
ax.spines['polar'].set_visible(False)
#设置y轴显示 # ax.set_yticklabels([0,1,2,3,4])
ax.set_xticks(angles[:-1]) ax.set_xticklabels(labels)
# 调整圆的间隔 # ax.set_rticks([0, 0.3, 0.6, 0.9, 1.2]) # 设置径向刻度的位置 ax.set_rlabel_position(15) # 设置径向刻度标签的位置
# plt.title(title)
# 添加图例loc='best', plt.legend(loc = (0.9, 0.95)) # fig.legend(loc='best')
return ax
# # 打印所有可用的样式列表 # for i in plt.style.available: #可读性 #DIV/0! # values = [ [4.088888889, 3.458730159, 3.576190476],[3.771428682, 2.492063381, 3.657142857]] # plot_radar_chart(['name', 'note', 'field'],values, '')
#语义 # [0.83521746,0.769798413,0.704907937,0.65028254,0.7487], [0.83521746,0.769798413,0.704907937,0.65028254,0.9366], # values = [ [0.83521746,0.769798413,0.704907937,0.65028254,1],[0.684297279,0.639577778 ,0.584657143,0.505793651,1]] # plot_radar_chart(['data model', 'state model','action', 'transfer', 'attribute'],values, '')
# values = [ [0.83521746,0.769798413,0.704907937,0.65028254,0.7487,4.088888889/5, 3.458730159/5, 3.576190476/5], # [0.684297279,0.639577778 ,0.584657143,0.505793651,1,3.771428682/5, 2.492063381/5, 3.657142857/5]] # plot_radar_chart(['data model', 'state model','action', 'transfer', 'attribute','name', 'note', 'field'],values, '')
# values = [ [0.83521746,0.769798413,0.704907937,0.65028254,0.9366,4.088888889/5, 3.458730159/5, 3.576190476/5], # [0.684297279,0.639577778 ,0.584657143,0.505793651,1,3.771428682/5, 2.492063381/5, 3.657142857/5]] # plot_radar_chart(['data model', 'state model','action', 'transfer', 'attribute','name', 'note', 'field'],values, '')
values = [ [0.83521746,0.769798413,0.704907937,0.65028254,1,4.088888889/5, 3.458730159/5, 3.576190476/5], [0.684297279,0.639577778 ,0.584657143,0.505793651,1,3.771428682/5, 2.492063381/5, 3.657142857/5]] plot_radar_chart(['DataModelNode', 'StateModelNode','Action', 'Transfer', 'Attribute','Name', 'Note', 'Field'],values, '')
plt.savefig('read.png', dpi=300) #指定分辨率保存 plt.show() plt.close()
|