【问题标题】:Windrose: Scatter plot wrscatter over contourfWindrose:等高线上的散点图 wrscatter
【发布时间】:2019-11-25 19:05:14
【问题描述】:

我想用 wrscatter 图覆盖使用 contourf() 制作的风玫瑰图。 这是我的 MWE:

import random
wind_dir = []; wind_speed = [];
for i in range(30):
    wind_dir.extend(random.sample(range(0, 359),1))
    wind_speed.extend(random.sample(range(0, 10),1))

import windrose
wd1 = np.radians([0, 45, 90, 135, 180, 225, 270, 315])
ws = [1.0, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95]
vf = np.vectorize(lambda wd: -wd + np.pi / 2)
wd = vf(wd1)

fig = plt.figure()
from windrose import WindroseAxes
plt.figure(figsize=(15,12))
ax = WindroseAxes.from_ax()
ax.contourf(wind_dir,wind_speed, bins=np.arange(0, 8, 1))
ax.set_legend()
windrose.wrscatter(wd, ws)
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5),prop={'size': 20})
plt.show()

现在这两个情节是分开的,但我希望它们重叠在一个情节中。 感谢您的帮助!

【问题讨论】:

    标签: python scatter contourf


    【解决方案1】:

    如果您将相同的轴添加到 wrscatter,它们将使用相同的绘图。

    import numpy as np
    from matplotlib import pyplot as plt
    import windrose
    
    wind_dir = np.random.uniform(0, 360, 50)
    wind_speed = np.random.uniform(0, 11, 50)
    
    wd1 = np.radians([0, 45, 90, 135, 180, 225, 270, 315])
    ws = [1.0, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95]
    vf = np.vectorize(lambda wd: -wd + np.pi / 2)
    wd = vf(wd1)
    
    ax = windrose.WindroseAxes.from_ax()
    ax.contourf(wind_dir, wind_speed, bins=np.arange(0, 8, 1))
    ax.set_legend()
    windrose.wrscatter(wd, ws, ax=ax)
    plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), prop={'size': 20})
    plt.show()
    

    【讨论】:

    • 谢谢!正是我想要的!
    猜你喜欢
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 2021-05-01
    • 2023-03-22
    • 2020-06-12
    • 2013-10-19
    相关资源
    最近更新 更多