亲宝软件园·资讯

展开

PYTHON绘制雷达图代码实例

人气:0

这篇文章主要介绍了PYTHON绘制雷达图代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1、雷达图

import matplotlib.pyplot as plt
import numpy as np

values = [0.09,-0.05,0.20,-0.02,0.08,0.09,0.03,0.027]
x = np.linspace(0,2*np.pi,9)[:-1]
c = np.random.random(size=(8,3))
fig = plt.figure()
plt.axes(polar=True)
#获取当前的axes
print(plt.gca())
#绘图
plt.bar(x,values,width=0.5,color=c,align='center')
plt.scatter(x,values,marker='o',c='black')
#添加文本
plt.figtext(0.03,0.7,s='陆地面积增长指数',fontproperties='KaiTi',fontsize=22,rotation='vertical',verticalalignment='center',horizontalalignment='center')

plt.ylim(-0.05, 0.25)

labels = np.array(['省1','省2','省3','省4','省5','省6','省7','研究区'])
dataLength = 8
angles = np.linspace(0, 2*np.pi, dataLength, endpoint=False)
plt.thetagrids(angles * 180/np.pi, labels,fontproperties='KaiTi',fontsize=18)

#添加注释
# plt.annotate(s='省',xy=(0,0.09),xytext=(0,0.28),fontproperties='KaiTi',fontsize=18)
# plt.annotate(s='省',xy=(0,-0.05),xytext=(np.pi/4,0.28),fontproperties='KaiTi',fontsize=18)
# plt.annotate(s='省',xy=(0,0.20),xytext=(np.pi/2,0.28),fontproperties='KaiTi',fontsize=18)
# plt.annotate(s='省',xy=(0,-0.02),xytext=(3*np.pi/4,0.33),fontproperties='KaiTi',fontsize=18)
# plt.annotate(s='省',xy=(0,0.08),xytext=(np.pi,0.38),fontproperties='KaiTi',fontsize=18)
# plt.annotate(s='省',xy=(0,0.09),xytext=(np.pi*5/4,0.35),fontproperties='KaiTi',fontsize=18)
# plt.annotate(s='前江省',xy=(0,0.03),xytext=(np.pi*3/2,0.30),fontproperties='KaiTi',fontsize=18)
# plt.annotate(s='研究区',xy=(0,0.027),xytext=(np.pi*7/4,0.28),fontproperties='KaiTi',fontsize=18)
#设置网格线样式
plt.grid(c='gray',linestyle='--',)


# y1 = [-0.05,0.0,0.05,0.10,0.15,0.20,0.25]
# lai=fig.add_axes([0.12,0.01,0.8,0.98])
# lai.patch.set_alpha(0.25)
# lai.set_ylim(-0.05, 0.25)
#显示
plt.show()

结果:

2、实例2

import matplotlib.pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['SimHei'] # 图例中文问题
plt.rcParams['axes.unicode_minus'] = False  #正负号问题


x= np.array(['1省','2省','3省','4省','5省','6省','7省','研究区'])
y1 = np.array([5.5, 7.2, 17.3, 15.0, 10.8, 21.8, 3.4, 81.4])
y2 = [0, -27.5, -3.9, -18.0, -0.2, -1.4, -1.7, -52.1]
y3 = [5.5, -20.2, 13.4, -2.9, 10.6, 20.4, 1.7, 28.5]


loc=[0.12,0.15,0.65,0.6]
plt.axes(loc)

plt.bar(x,y1,0.4,label=u'退')
plt.bar(x,y2,0.4,label=u'进')
plt.plot(x,y3,marker='o',markersize='6',c='black')

y=np.array([-50, 0 ,50])
plt.xticks(x,fontproperties='KaiTi',fontsize=8)
plt.yticks(y)
plt.grid(c='gray',linestyle='--',alpha=0.25)

plt.figtext(0.02,0.45,s='变化(km2)',fontproperties='KaiTi',fontsize=14,rotation='vertical',verticalalignment='center',horizontalalignment='center')


#frameon=False 去掉图例边框
plt.legend(loc='center', bbox_to_anchor=(1.2, 0.5),ncol=1,
      frameon=False)

plt.show()

结果:

您可能感兴趣的文章:

加载全部内容

相关教程
猜你喜欢
用户评论