Hexbin Plot
Temperature Pressure Correlation
Weather data hexbin showing temperature vs atmospheric pressure relationship
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(123)
temp = np.random.normal(20, 8, 6000)
pressure = 1013 - 0.5 * temp + np.random.normal(0, 3, 6000)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#ffffff')
ax.set_facecolor('#f0f9ff')
colors = ['#f0f9ff', '#bae6fd', '#7dd3fc', '#38bdf8', '#0ea5e9', '#0284c7', '#0369a1', '#075985']
cmap = LinearSegmentedColormap.from_list('sky', colors, N=256)
hb = ax.hexbin(temp, pressure, gridsize=25, cmap=cmap, mincnt=1, edgecolors='white', linewidths=0.3)
cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.outline.set_edgecolor('#bae6fd')
cbar.ax.tick_params(colors='#0369a1', labelsize=9)
cbar.set_label('Observations', color='#0369a1', fontsize=10)
ax.set_xlabel('Temperature (°C)', color='#0369a1', fontsize=11)
ax.set_ylabel('Pressure (hPa)', color='#0369a1', fontsize=11)
ax.tick_params(colors='#0369a1', labelsize=10)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#bae6fd')
ax.spines['bottom'].set_color('#bae6fd')
plt.tight_layout()
Library
Matplotlib
Category
Pairwise Data
More Hexbin Plot examples
☕