python数据分析实训任务二(‘风力风向’)
import numpy as np
import matplotlib.pyplot as plt
# 数据
labels=np.array(['东风', '东北风', '北风', '西北风', '西风', '西南风', '南风', '东南风'])
stats=np.array([2.1, 2, 0, 3, 1.5, 3, 6, 4])
# 将角度转换为弧度
angles=np.linspace(0, 2*np.pi, len(labels), endpoint=False).tolist()
# 使图形闭合
stats=np.concatenate((stats, [stats[0]]))
angles+=angles[:1]
# 绘图
fig, ax = plt.subplots(figsize=(10,10), subplot_kw=dict(polar=True))
ax.fill(angles, stats, color='blue', alpha=0.25)
ax.plot(angles, stats, color='blue', linewidth=4) # 绘制线条
# 添加标签
ax.set_xticklabels(labels)
# 添加标题
ax.set_title('风力属性')
plt.show()