%matplotlib inline
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
from math import pi
from windrose import WindroseAxes
N = 500
ws = np.random.random(N)*6
wd = np.random.random(N)*360
df = pd.DataFrame({"speed": ws, "direction": wd})
df
direction | speed | |
---|---|---|
0 | 215.262198 | 3.097674 |
1 | 319.188158 | 4.853040 |
2 | 275.980176 | 5.391387 |
3 | 91.111268 | 3.708316 |
4 | 266.453726 | 2.298292 |
5 | 155.509724 | 4.989684 |
6 | 333.902822 | 4.456108 |
7 | 177.208871 | 4.568336 |
8 | 306.216666 | 2.069329 |
9 | 105.776877 | 3.106843 |
10 | 292.404955 | 3.610744 |
11 | 144.199129 | 4.388195 |
12 | 223.580591 | 4.032557 |
13 | 350.454358 | 3.838077 |
14 | 168.200246 | 1.759043 |
15 | 321.778093 | 4.245708 |
16 | 329.518157 | 3.296086 |
17 | 93.787206 | 1.738636 |
18 | 318.695791 | 4.860143 |
19 | 271.512474 | 2.275167 |
20 | 345.167955 | 0.167950 |
21 | 204.396710 | 5.241221 |
22 | 306.748871 | 4.571908 |
23 | 180.211004 | 5.087667 |
24 | 256.064927 | 2.347778 |
25 | 94.701413 | 4.673976 |
26 | 152.465427 | 5.782738 |
27 | 224.871745 | 1.020907 |
28 | 90.549226 | 5.344184 |
29 | 301.315502 | 5.189904 |
... | ... | ... |
470 | 359.391320 | 3.649401 |
471 | 207.018491 | 4.315531 |
472 | 159.883184 | 4.384715 |
473 | 119.002422 | 5.267992 |
474 | 172.405694 | 0.921656 |
475 | 179.992617 | 2.136770 |
476 | 135.081384 | 0.010645 |
477 | 359.436428 | 0.692742 |
478 | 50.440449 | 3.756566 |
479 | 190.887721 | 4.500391 |
480 | 270.809735 | 2.267938 |
481 | 177.123526 | 0.591785 |
482 | 62.060480 | 1.082086 |
483 | 97.018199 | 2.401951 |
484 | 335.674333 | 5.915831 |
485 | 338.363379 | 3.688760 |
486 | 206.995024 | 3.605537 |
487 | 302.611193 | 0.959565 |
488 | 156.178855 | 3.432469 |
489 | 53.498967 | 4.417359 |
490 | 61.148478 | 3.364768 |
491 | 121.051504 | 1.898999 |
492 | 38.658609 | 5.562019 |
493 | 10.665699 | 0.645992 |
494 | 272.843433 | 1.153355 |
495 | 277.176995 | 4.540049 |
496 | 329.515710 | 3.244110 |
497 | 110.457168 | 5.390673 |
498 | 26.037311 | 3.559466 |
499 | 235.266073 | 3.510471 |
500 rows × 2 columns
df['speed_x'] = df['speed'] * np.sin(df['direction'] * pi / 180.0)
df['speed_y'] = df['speed'] * np.cos(df['direction'] * pi / 180.0)
fig, ax = plt.subplots(figsize=(8, 8), dpi=80)
x0, x1 = ax.get_xlim()
y0, y1 = ax.get_ylim()
ax.set_aspect('equal')
_ = df.plot(kind='scatter', x='speed_x', y='speed_y', alpha=0.35, ax=ax)
ax = WindroseAxes.from_ax()
ax.bar(df.direction, df.speed, normed=True, opening=0.8, edgecolor='white')
ax.set_legend()
ax = WindroseAxes.from_ax()
ax.box(df.direction, df.speed, bins=np.arange(0, 8, 1))
ax.set_legend()
ax = WindroseAxes.from_ax()
ax.contourf(df.direction, df.speed, bins=np.arange(0, 8, 1), cmap=cm.hot)
ax.set_legend()
ax = WindroseAxes.from_ax()
ax.contourf(df.direction, df.speed, bins=np.arange(0, 8, 1), cmap=cm.hot)
ax.contour(df.direction, df.speed, bins=np.arange(0, 8, 1), colors='black')
ax.set_legend()
ax = WindroseAxes.from_ax()
ax.contour(df.direction, df.speed, bins=np.arange(0, 8, 1), cmap=cm.hot, lw=3)
ax.set_legend()