python然后画风矢杆图
时间: 2024-09-29 11:12:29 浏览: 88
在Python中,你可以使用matplotlib库来绘制风矢杆图。以下是一个简单的例子,展示如何利用matplotlib和方向箭头来创建这样一个图:
```python
import matplotlib.pyplot as plt
from matplotlib.patches import Arrow
def draw_windrose(ax, direction, speed, N=8):
# 创建等分角度
angles = [n * 45 for n in range(N)]
# 初始化速度列表
speed_list = [speed] * len(direction)
# 绘制风向箭头
for angle, spd in zip(angles, speed_list):
ax.add_patch(Arrow(0, 0, spd * np.cos(np.radians(angle)), spd * np.sin(np.radians(angle)),
width=0.01, head_width=0.05, color='k'))
# 添加风向标签
ax.set_xticks(angles, labels=['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'])
ax.set_yticks([])
# 设置轴范围
ax.set_xlim(-1.1, 1.1)
ax.set_ylim(-1.1, 1.1)
ax.axis('equal') # 确保圆心对齐
# 示例数据
directions = [0, 45, 90, 135, 180, 225, 270, 315]
speeds = [10, 20, 15, 10, 5, 5, 10, 15]
# 创建一个新的图形并添加子图
fig, ax = plt.subplots()
draw_windrose(ax, directions, speeds)
plt.title("示例风矢杆图")
plt.show()
阅读全文
相关推荐






