# 雷达图 二级分类
def draw_polar(col='二级分类', n=8):
a = od.groupby(['门店名称', col]).单项数量.sum().unstack(level=0).fillna(0)
a['共计'] = a.agg(sum, axis=1); a = a/a.sum()
# 以共计排序
a = a.sort_values('共计', ascending=False).iloc[:n]
ax1= plt.subplot(111, projection='polar')
angle = np.linspace(0, 2*np.pi, n, endpoint=False) #data里有几个数据,就把整圆360°分成几份
angles = np.concatenate((angle, [angle[0]])) #增加第一个angle到所有angle里,以实现闭合
ax1.set_thetagrids(angles*180/np.pi, a.index, color='#574e4f') #设置网格标签3
colors = ['#1f77b4','pink','orange']
for i,md in enumerate(a.columns[:3]):
globals()['data%s'%(i+1)] = a[md].values
globals()['data%s'%(i+1)] = np.concatenate((globals()['data%s'%(i+1)], [globals()['data%s'%(i+1)][0]])) # 实现闭合
ax1.plot(angles,globals()['data%s'%(i+1)],'o--',label=md, color=colors[i], alpha=0.8) # #b1defd
ax1.fill(angles,globals()['data%s'%(i+1)], color=colors[i], alpha=0.4)
plt.legend(ncol=3, bbox_to_anchor=(1.3, -0.1))
plt.title(col+'\n')
draw_polar()
https://www.cnblogs.com/hhh5460/p/4361610.html
a = com[rating_col].count().sort_values(ascending=False)
labels = a.index
data = a.values
dataLenth = len(a)
angles = np.linspace(0, 2*np.pi, dataLenth, endpoint=False)
data = np.concatenate((data, [data[0]])) # 闭合
angles = np.concatenate((angles, [angles[0]])) # 闭合
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)# polar参数!!
ax.plot(angles, data, 'bo-', linewidth=2)# 画线
ax.fill(angles, data, facecolor='r', alpha=0.25)# 填充
ax.set_thetagrids(angles * 180/np.pi, labels, fontproperties="SimHei")
ax.set_title("matplotlib雷达图", va='bottom', fontproperties="SimHei")
ax.set_rlim(4.1,5)
ax.grid(True)