Hexbin Plot

Sensor Calibration Data

Industrial sensor calibration hexbin with expected vs measured values

Output
Sensor Calibration Data
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(321)
expected = np.random.uniform(0, 100, 6000)
measured = expected + np.random.normal(0, 3, 6000) + 0.02 * expected

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

colors = ['#fef9c3', '#fde047', '#facc15', '#eab308', '#ca8a04', '#a16207', '#854d0e', '#713f12']
cmap = LinearSegmentedColormap.from_list('amber', colors, N=256)

hb = ax.hexbin(expected, measured, gridsize=28, 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('#fde047')
cbar.ax.tick_params(colors='#854d0e', labelsize=9)
cbar.set_label('Samples', color='#854d0e', fontsize=10)

ax.plot([0, 100], [0, 100], '--', color='#ca8a04', linewidth=1.5, alpha=0.7, label='Ideal')

ax.set_xlabel('Expected Value', color='#854d0e', fontsize=11)
ax.set_ylabel('Measured Value', color='#854d0e', fontsize=11)
ax.tick_params(colors='#854d0e', labelsize=10)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#fde047')
ax.spines['bottom'].set_color('#fde047')
ax.legend(loc='upper left', facecolor='#fef9c3', edgecolor='#fde047')

plt.tight_layout()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support