1

I'd like to put in the same figure a normal line plot and a windrose, but I can't manage. My result is 2 figures one with the line plot and an empty plot and the second figure is the windrose, how can i put together, in the same figure. The code that I've been using is below:

fig, (ax1, ax2) = plt.subplots(1, 2)
data['velocidad_x'] = data['wind_s'] * np.sin(data['wind_dir'] * pi / 180.0)
data['velocidad_y'] = data['wind_s'] * np.cos(data['wind_dir'] * pi / 180.0)
x0, x1 = ax1.get_xlim()
y0, y1 = ax1.get_ylim()
ax1.set_aspect('equal')
_ = data.plot(kind='scatter', x='velocidad_x', y='velocidad_y', alpha=0.35, ax=ax)
ax1=WindroseAxes.from_ax()
ax1.bar(data['wind_dir'], data['wind_s'], normed=True, opening=0.8, edgecolor='white')
ax2.plot(data['wind_dir'].resample('1min').mean())
plt.title('xxxxx',fontsize=17)
ax1.set_legend()
ax1.legend(title="Wind speed (m/s)")  

fig.tight_layout()
plt.gcf().set_size_inches(8,6)  
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
renton
  • 51
  • 5

1 Answers1

0

Try the following code:

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

ws = numpy.random.uniform(low = 2, high = 8, size = 500)
wd = numpy.random.uniform(low = 0, high = 360, size = 500)
time = numpy.arange(0, 500, 1, dtype=int)

fig = plt.figure(figsize=(10, 7))

ax0 = fig.add_subplot(111)
ax0.plot(time, ws)

plt.gca().set_ylim(bottom=0,top=35)
rect=[0.55, 0.47, 0.35, 0.35]
wa=WindroseAxes(fig, rect)
fig.add_axes(wa)
wa.bar(wd, ws, normed=True, opening=0.8, edgecolor='white')

plt.show()

enter image description here