You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将气候平均与当月的两个风玫瑰图叠加为单个风玫瑰图?

叠加两组风玫瑰图的实现方法
  • 核心思路:复用同一个WindroseAxes坐标轴实例,分别对两组数据调用bar()方法,通过颜色、透明度、标签区分气候平均与当月数据。
  • 注意事项:确保两组数据使用相同的风速区间(bins参数一致),保证可视化的可比性。

完整代码示例

import matplotlib.pyplot as plt
from windrose import WindroseAxes
import numpy as np

# 统一风速区间,保证两组数据对比一致
speed_bins = np.arange(0, 10, 1)

# 创建风玫瑰坐标轴
ax = WindroseAxes.from_ax()

# 绘制气候平均风玫瑰:蓝色系半透明,添加标签
cmap_avg = plt.get_cmap('Blues')
ax.bar(df1.winddir, df1.wind_speed, normed=True, opening=0.8, bins=speed_bins,
       cmap=cmap_avg, edgecolor='white', alpha=0.7, label='气候平均')

# 绘制当月风玫瑰:橙色系半透明,添加标签
cmap_current = plt.get_cmap('Oranges')
ax.bar(df2.winddir, df2.wind_speed, normed=True, opening=0.8, bins=speed_bins,
       cmap=cmap_current, edgecolor='white', alpha=0.7, label='当月数据')

# 设置图例与标题
ax.set_title("风速 (m/s)", y=1.05)
ax.legend(title="数据组", loc='upper right', bbox_to_anchor=(1.3, 1))

plt.show()

关键细节说明

  • 复用坐标轴:无需创建多个子图,直接在同一个ax对象上连续调用bar()即可实现叠加。
  • 统一参数:bins、opening等参数保持一致,避免可视化偏差。
  • 样式区分:通过cmap(配色)、alpha(透明度)、label(图例标签)让两组数据清晰可辨。
  • 图例优化:调整图例位置避免遮挡,添加标题明确数据含义。

内容的提问来源于stack exchange,提问作者user2100039

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 00:45:59