给出一组风向、风力、风速数据,利用python绘制带箭头的风向、风力、风速图
时间: 2023-12-22 22:03:59 浏览: 92
带箭头的风速、风向图.xlsx
5星 · 资源好评率100%
在 Python 中,可以使用 matplotlib 库绘制风向、风力、风速图。以下是示例代码:
```python
import matplotlib.pyplot as plt
import numpy as np
# 风向、风力、风速数据
wind_direction = np.array([0, 45, 90, 135, 180, 225, 270, 315])
wind_speed = np.array([1, 2, 3, 4, 5, 6, 7, 8])
wind_power = np.array([0.2, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
# 极坐标系下的角度
angles = np.deg2rad(90 - wind_direction)
# 绘制风向图
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)
ax.set_rlim(0, 8)
ax.set_rticks([1, 2, 3, 4, 5, 6, 7, 8])
ax.set_rlabel_position(22.5)
ax.set_thetagrids(wind_direction, labels=None)
for angle, speed in zip(angles, wind_speed):
x = [angle, angle+0.1]
y = [0, speed]
ax.plot(x, y, color='blue')
ax.annotate("", xy=(angle+0.1, speed), xytext=(angle, 0),
arrowprops=dict(arrowstyle="->", color='blue'))
# 绘制风力图
fig, ax = plt.subplots()
ax.bar(wind_direction, wind_power, width=30, alpha=0.5)
ax.set_xlim(-15, 375)
ax.set_ylim(0, 6)
ax.set_xticks(wind_direction)
ax.set_xlabel('Wind Direction')
ax.set_ylabel('Wind Power')
# 绘制风速图
fig, ax = plt.subplots()
ax.plot(wind_direction, wind_speed, color='red')
ax.fill_between(wind_direction, wind_speed, alpha=0.5, color='red')
ax.set_xlim(-15, 375)
ax.set_ylim(0, 8)
ax.set_xticks(wind_direction)
ax.set_xlabel('Wind Direction')
ax.set_ylabel('Wind Speed')
plt.show()
```
运行上述代码,即可得到带箭头的风向图、风力图、风速图。其中,风向图使用极坐标系绘制,风力图使用柱状图绘制,风速图使用折线图绘制。
风向图:
![风向图](https://img-blog.csdnimg.cn/20220117194530313.png)
风力图:
![风力图](https://img-blog.csdnimg.cn/20220117194613771.png)
风速图:
![风速图](https://img-blog.csdnimg.cn/20220117194653540.png)
阅读全文