python绘制雷达图

在以前的研究中喜欢做各类因子与其中一个因子的相关系数,放在表格里面。但当时想到能用图片直观表达出来看哪个因子相关更高,于是做了雷达图,例如下面的图片,绘制的是各个因子和城市内涝相关性的绝对值。
请添加图片描述

python 代码如下,修改标签和数据部分即可:

# -*- coding: UTF-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams

config = {"font.family": 'serif',
          "font.size": 20,
          "mathtext.fontset": 'stix',
          #"font.serif": ["SimHei"],
          'axes.unicode_minus': False}
rcParams.update(config)

# 标签
labels = np.array(['Impervious Ratio', 'Green Area Ratio','Water Ratio', 'GDP','Population', 'Annual Precipitation' ])
# 数据个数
Len = 6
# 数据

data = np.array([0.47, 0.21, 0.25,0.6, 0.48,0.31])
angles = np.linspace(0, 2 * np.pi, Len, endpoint=False)
data = np.concatenate((data, [data[0]]))
angles = np.concatenate((angles, [angles[0]]))
labels = np.concatenate((labels, [labels[0]]))


fig = plt.figure(num=1, figsize=(12, 8))
ax = fig.add_subplot(111, polar=True)

for i in range(1,6):
    data1 = np.array([0.2, 0.2, 0.2, 0.2,0.2,0.2])*i
    data1 = np.concatenate((data1, [data1[0]]))
    ax.plot(angles, data1,linestyle='-', color='orange' ,linewidth=3)

# the data line
plt.plot(angles, data, linestyle='-', color='g', marker='o', ms=12, mfc='b', mec='c', linewidth=6.0)

# the label
ax.set_thetagrids(angles * 180 / np.pi, labels, fontproperties="SimHei")
ax.set_xticklabels([''] * len(labels))
for x,y,label in zip(angles, np.array([1.3,1,1,1,1,1])*1.2,labels):
    plt.text(x, y, label, ha="center", va="baseline", fontsize=22)

ax.grid(False)
#ax.set_rlim(0, 1.1)
ax.set_rlim(0, 1.1)
plt.axis("off")
plt.savefig('Correlation.jpg',dpi=600)
#plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宇天y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值