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