0

I'd like to overlay a wind rose made with contourf() with a wrscatter plot. This is my 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()

Now the two plots are separate but I'd like them to be overlain in one plot. Appreciate the help!

1 Answers1

0

If you add the same axis to wrscatter, they'll use the same plot.

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()

sample plot

JohanC
  • 71,591
  • 8
  • 33
  • 66