Hexbin Plot

Wind Speed Direction

Meteorological hexbin of wind velocity components

Output
Wind Speed Direction
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(999)
# Prevailing westerly winds
u = np.random.normal(5, 3, 7000)
v = np.random.normal(0, 2, 7000)

fig, ax = plt.subplots(figsize=(10, 8), facecolor='#0f0f1a')
ax.set_facecolor('#0f0f1a')

colors = ['#0f0f1a', '#1a1f3a', '#2a3f5a', '#3a5f7a', '#4a8f9a', '#5abfba', '#7adfda', '#aaffff']
cmap = LinearSegmentedColormap.from_list('teal', colors, N=256)

hb = ax.hexbin(u, v, gridsize=32, cmap=cmap, mincnt=1, edgecolors='none')

cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.ax.set_facecolor('#0f0f1a')
cbar.outline.set_edgecolor('#2a3f5a')
cbar.ax.tick_params(colors='#5abfba', labelsize=9)
cbar.set_label('Observations', color='#5abfba', fontsize=10)

ax.axhline(0, color='#2a3f5a', linewidth=0.5, linestyle='--')
ax.axvline(0, color='#2a3f5a', linewidth=0.5, linestyle='--')
ax.set_xlabel('U Component (m/s)', color='#5abfba', fontsize=11)
ax.set_ylabel('V Component (m/s)', color='#5abfba', fontsize=11)
ax.tick_params(colors='#5abfba', labelsize=10)
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support