雷达图
- 最终效果

import numpy as np
import matplotlib.pyplot as plt
'''设置允许中文绘图'''
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
def plot_ladar(values, labels=None, _max=None):
line_color = np.array([215, 215, 215])/255
d_color = np.array([47, 126, 216])/255
if not labels:
labels = range(len(values))
if not _max:
_max = np.max(values)
n = len(values)
angles = np.concatenate((np.linspace(0, 2*np.pi, n, endpoint=False), [0]))
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
for ang in angles:
ax.plot([ang]*2, [0, _max], '-', c=line_color)
tick = 3
for i in range(tick):
ax.plot(angles, [_max*(1/tick)*(i+1)]*(n+1), c = line_color)
ax.plot(angles, values+[values[0]], "-", c = d_color)
ax.plot(angles, values+[values[0]], "o", c = d_color)
ax.set_thetagrids(angles * 180 / np.pi, labels)
ax.set_theta_zero_location('N')
ax.spines['polar'].set_visible(False)
ax.grid(False)
ax.set_yticks([])
return plt
if __name__ == "__main__":
p = plot_ladar([10, 30, 49, 43, 78],
labels=['速度', '防御', '攻击', '魔法', '回复'])
p.show()