球员能力值图

#_*_coding:utf-8 _*_
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

plt.style.use('ggplot')
font=FontProperties(fname=r'C:WindowsFontsSTXINGKA.TTF',size=10)
ability_size=6
ability_label=[u'进攻',u'防守',u'盘带',u'速度',u'体力',u'射术']

ax1=plt.subplot(221,projection='polar')
ax2=plt.subplot(222,projection='polar')
ax3=plt.subplot(223,projection='polar')
ax4=plt.subplot(224,projection='polar')

player={
'A':np.random.randint(size=ability_size,low=60,high=99),
'B':np.random.randint(size=ability_size,low=60,high=99),
'C':np.random.randint(size=ability_size,low=60,high=99),
'D':np.random.randint(size=ability_size,low=60,high=99),
}


theta=np.linspace(0,2*np.pi,6,endpoint=False)

theta=np.append(theta,theta[0])

player['A']=np.append(player['A'],player['A'][0])
ax1.plot(theta,player['A'],'r')
ax1.fill(theta,player['A'],'r',alpha=0.2)
ax1.set_xticks(theta)
ax1.set_xticklabels(ability_label,y=0.01,fontproperties=font)
ax1.set_title(u'球员A',position=(0.5,0.99),fontproperties=font,color='red',size=20)


player['B']=np.append(player['B'],player['B'][0])
ax2.plot(theta,player['B'],'g')
ax2.fill(theta,player['B'],'g',alpha=0.2)
ax2.set_xticks(theta)
ax2.set_xticklabels(ability_label,y=0.01,fontproperties=font)
ax2.set_title(u'球员B',position=(0.5,0.99),fontproperties=font,color='green',size=20)

player['C']=np.append(player['C'],player['C'][0])
ax3.plot(theta,player['C'],'b')
ax3.fill(theta,player['C'],'b',alpha=0.2)
ax3.set_xticks(theta)
ax3.set_xticklabels(ability_label,y=0.01,fontproperties=font)
ax3.set_title(u'球员C',position=(0.5,0.99),fontproperties=font,color='blue',size=20)

player['D']=np.append(player['D'],player['D'][0])
ax4.plot(theta,player['D'],'y')
ax4.fill(theta,player['D'],'y',alpha=0.2)
ax4.set_xticks(theta)
ax4.set_xticklabels(ability_label,y=0.01,fontproperties=font)
ax4.set_title(u'球员D',position=(0.5,0.99),fontproperties=font,color='yellow',size=20)
plt.show()

这是我的代码

以下是效果图:

 能力值使用numpy的随机库生成的

最难的还是编码问题,起初把汉字搞上去的时候会出现编码错误,后来在开头加了编码的注释发现还是显示不出来,但是不会报错了

查了好多最后才发现问题不在python,在matplotlib,于是上官网看了一下有个fontproperties的类,可以从系统引入字体路径,才得已解决。

原文地址:https://www.cnblogs.com/xiaomei123/p/12900417.html