利用matplotlib绘制雷达图,数据为label:数学,语文,地理,历史,体育,化学,对应的成绩为99.67,78,89,90,56
时间: 2023-05-22 09:07:15 浏览: 116
可以使用以下代码来绘制雷达图:
import numpy as np
import matplotlib.pyplot as plt
# 数据
labels = ['数学', '语文', '地理', '历史', '体育', '化学']
scores = [99.67, 78, 89, 90, 56]
# 利用numpy将labels均分为6份
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False)
# 将第一个label放在最上面,为了美观,再次append第一个label
angles = np.concatenate((angles, [angles[0]]))
# 将scores的最后一个元素移动到第一位,为了美观,再次append最后一个元素
scores = np.concatenate((scores[-1:], scores[:-1]))
fig = plt.figure()
ax = fig.add_subplot(111, polar=True) # polar参数表示极坐标系
# 绘制折线图
ax.plot(angles, scores, 'o-', linewidth=2)
# 填充颜色
ax.fill(angles, scores, alpha=0.25)
# 添加标签
ax.set_thetagrids(angles * 180 / np.pi, labels, fontproperties="SimHei")
# 设置标题
plt.title('雷达图', fontproperties="SimHei")
# 显示图形
plt.show()
阅读全文
相关推荐










