先参考文献:https://www.matplotlib.org
需求1.填写B和C的各科成绩:
import numpy as np
import matplotlib.pyplot as plt
# 0.设置中文
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
# 1.准备大数据专业三位同学各科目成绩
dim_num = 6
radians = np.linspace(0, 2 * np.pi, dim_num, endpoint=False)
radians = np.concatenate((radians, [radians[0]]))
# A同学: '数学','英语','线代','爬虫','数据可视化','吃喝玩乐' ---> 41,38,36,62,68,100
score_a = np.array([41,38,36,62,68,100])
score_a = np.concatenate((score_a, [score_a[0]]))
# B同学:'数学','英语','线代','爬虫','数据可视化','吃喝玩乐' ---> 91,88,83,72,78,26
# C同学:'数学','英语','线代','爬虫','数据可视化','吃喝玩乐' ---> 81,78,85,76,74,36
import numpy as np
import matplotlib.pyplot as plt
# 0.设置中文
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
# 1.准备大数据专业三位同学各科目成绩
dim_num = 6
radians = np.linspace(0, 2 * np.pi, dim_num, endpoint=False)
radians = np.concatenate((radians, [radians[0]]))
# A同学: '数学','英语','线代','爬虫','数据可视化','吃喝玩乐' ---> 41,38,36,62,68,100
score_a = np.array([41,38,36,62,68,100])
score_a = np.concatenate((score_a, [score_a[0]]))
# B同学:'数学','英语','线代','爬虫','数据可视化','吃喝玩乐' ---> 91,88,83,72,78,26
score_b = np.array([91,88,83,72,78,26])
score_b = np.concatenate((score_b, [score_b[0]]))
# C同学:'数学','英语','线代','爬虫','数据可视化','吃喝玩乐' ---> 81,78,85,76,74,36
score_c = np.array([81,78,85,76,74,36])
score_c = np.concatenate((score_c, [score_c[0]]))
把B和C的成绩用雷达图表示:
# 1.绘制多边形(雷达图)
#——————————————————————————————————————————
plt.polar(radians, score_a, 'r', label='A同学') # A同学的成绩
plt.polar(radians, score_b, 'y', label='B同学') # B同学的成绩
plt.polar(radians, score_c, 'k', label='C同学') # C同学的成绩
#——————————————————————————————————————————
# 2.设置维度标签
radar_labels = ['数学','英语','线代','爬虫','数据可视化','吃喝玩乐']
radar_labels = np.concatenate((radar_labels, [radar_labels[0]])) # 拼接一下,构成闭环 (此处可以不拼接,为了统一而已)
# 3.设置极坐标的标签
angles = radians * 180/np.pi # 弧度转角度
plt.thetagrids(angles, labels=radar_labels) # 设置新的刻度标签
# 4.填充多边形
#——————————————————————————————————————————
plt.fill(radians, score_a, 'r', alpha=0.25) # A同学的成绩
plt.fill(radians, score_b, 'y', alpha=0.25) # B同学的成绩
plt.fill(radians, score_c, 'k', alpha=0.25) # C同学的成绩
#——————————————————————————————————————————
# 5.展示图表
plt.show()