我想用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()
现在,两个地块是分开的,但我希望它们在一个地块上重叠。 感谢帮助!
答案 0 :(得分:0)
如果将相同的轴添加到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()