1

there is a beautiful example of subplots display with windroses but I don't find any code of it, and for me the function windroseaxes is a blackbox.

Here is my code, it's generate 2 plots of windrose and I try to have one plot with two subplots :

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

ws1 = np.random.random(500) * 6
wd1 = np.random.random(500) * 360
ws2 = np.random.random(500) * 6
wd2 = np.random.random(500) * 360

fig, ax = plt.subplots(2, figsize=(15,15), dpi=150)

ax[0] = WindroseAxes.from_ax()
ax[0].contourf(wd1, ws1, bins=np.arange(0, 8, 1), cmap=cm.hot)
ax[0].contour(wd1, ws1, bins=np.arange(0, 8, 1), colors='black')
ax[1] = WindroseAxes.from_ax()
ax[1].contourf(wd2, ws2, bins=np.arange(0, 8, 1), cmap=cm.hot)
ax[1].contour(wd2, ws2, bins=np.arange(0, 8, 1), colors='black')
# ax.set_legend()
BenjiBoy
  • 141
  • 7

1 Answers1

1

I figured it out (with severals stack posts that I can't all post here), here a sample code :

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

ws1 = np.random.random(500) * 6
wd1 = np.random.random(500) * 360
ws2 = np.random.random(500) * 6
wd2 = np.random.random(500) * 360
ws3 = np.random.random(500) * 6
wd3 = np.random.random(500) * 360
ws4 = np.random.random(500) * 6
wd4 = np.random.random(500) * 360

fig=plt.figure(figsize=(15,15),dpi=150)
# rect = [lowerleft_x,lowerleft_y,width,height]

opening=0.99


rect1=[0.1, 0.5, 0.4, 0.4] 
wa1=WindroseAxes(fig, rect1)
fig.add_axes(wa1)
wa1.set_title('00:00 - 06:00')
wa1.bar(wd1, ws1, normed=True, opening=opening, edgecolor='white')

rect2=[0.6, 0.5, 0.4, 0.4]
wa2=WindroseAxes(fig, rect2)
fig.add_axes(wa2)
wa2.set_title('06:00 - 12:00')
wa2.bar(wd2, ws2, normed=True, opening=opening, edgecolor='white')

rect3=[0.1,0,0.4,0.4] 
wa3=WindroseAxes(fig, rect3)
fig.add_axes(wa3)
wa3.set_title('12:00 - 18:00')
wa3.bar(wd3, ws3, normed=True, opening=opening, edgecolor='white')

rect4=[0.6,0,0.4,0.4] 
wa4=WindroseAxes(fig, rect4)
fig.add_axes(wa4)
wa4.set_title('18:00 - 00:00')
wa4.bar(wd4, ws4, normed=True, opening=opening, edgecolor='white')
wa4.set_legend()

enter image description here

Note that is very bad centred and I just put a legend but this is the wa4 legend only, and don't pay attention to the title, that's for my data. But you have the most important part :-)!

BenjiBoy
  • 141
  • 7