Hexbin Plot
Seismic Wave Velocity
Geophysics hexbin showing P-wave vs S-wave velocities in rock samples
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(7777)
p_wave = np.random.uniform(2, 8, 6000)
s_wave = p_wave / 1.73 + np.random.normal(0, 0.3, 6000)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#1a1a1a')
ax.set_facecolor('#1a1a1a')
colors = ['#1a1a1a', '#2a2a3a', '#3a4a5a', '#4a6a7a', '#5a8a9a', '#7abaaa', '#9adaba', '#bafafa']
cmap = LinearSegmentedColormap.from_list('seismic', colors, N=256)
hb = ax.hexbin(p_wave, s_wave, gridsize=30, cmap=cmap, mincnt=1, edgecolors='none')
cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.ax.set_facecolor('#1a1a1a')
cbar.outline.set_edgecolor('#3a4a5a')
cbar.ax.tick_params(colors='#7abaaa', labelsize=9)
cbar.set_label('Samples', color='#7abaaa', fontsize=10)
# Add theoretical Vp/Vs = 1.73 line
ax.plot([2, 8], [2/1.73, 8/1.73], '--', color='#5a8a9a', linewidth=1.5, alpha=0.7, label='Vp/Vs=1.73')
ax.set_xlabel('P-wave Velocity (km/s)', color='#7abaaa', fontsize=11)
ax.set_ylabel('S-wave Velocity (km/s)', color='#7abaaa', fontsize=11)
ax.tick_params(colors='#7abaaa', labelsize=10)
ax.legend(loc='upper left', facecolor='#1a1a1a', edgecolor='#3a4a5a', labelcolor='#7abaaa')
for spine in ax.spines.values():
spine.set_visible(False)
plt.tight_layout()
Library
Matplotlib
Category
Pairwise Data
More Hexbin Plot examples
☕