Hexbin Plot
Ocean Salinity Depth
Oceanography hexbin showing salinity vs depth measurements
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(4444)
depth = np.random.exponential(500, 6000)
salinity = 35 + 0.002 * depth + np.random.normal(0, 0.5, 6000)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#0c1929')
ax.set_facecolor('#0c1929')
colors = ['#0c1929', '#0c4a6e', '#0369a1', '#0284c7', '#0ea5e9', '#38bdf8', '#7dd3fc', '#bae6fd']
cmap = LinearSegmentedColormap.from_list('ocean', colors, N=256)
hb = ax.hexbin(salinity, -depth, gridsize=30, cmap=cmap, mincnt=1, edgecolors='none')
cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.ax.set_facecolor('#0c1929')
cbar.outline.set_edgecolor('#0c4a6e')
cbar.ax.tick_params(colors='#38bdf8', labelsize=9)
cbar.set_label('Samples', color='#38bdf8', fontsize=10)
ax.set_xlabel('Salinity (PSU)', color='#38bdf8', fontsize=11)
ax.set_ylabel('Depth (m)', color='#38bdf8', fontsize=11)
ax.tick_params(colors='#38bdf8', labelsize=10)
for spine in ax.spines.values():
spine.set_visible(False)
plt.tight_layout()
Library
Matplotlib
Category
Pairwise Data
More Hexbin Plot examples
☕