Hexbin Plot
Battery Discharge Curve
Electronics hexbin showing voltage vs current during discharge
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(3333)
voltage = np.random.uniform(2.8, 4.2, 6000)
current = (4.2 - voltage) * 500 + np.random.normal(0, 50, 6000)
current = np.clip(current, 0, 1000)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#ecfdf5')
ax.set_facecolor('#d1fae5')
colors = ['#d1fae5', '#a7f3d0', '#6ee7b7', '#34d399', '#10b981', '#059669', '#047857', '#065f46']
cmap = LinearSegmentedColormap.from_list('emerald', colors, N=256)
hb = ax.hexbin(voltage, current, 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('#a7f3d0')
cbar.ax.tick_params(colors='#047857', labelsize=9)
cbar.set_label('Measurements', color='#047857', fontsize=10)
ax.set_xlabel('Voltage (V)', color='#047857', fontsize=11)
ax.set_ylabel('Current (mA)', color='#047857', fontsize=11)
ax.tick_params(colors='#047857', labelsize=10)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#a7f3d0')
ax.spines['bottom'].set_color('#a7f3d0')
plt.tight_layout()
Library
Matplotlib
Category
Pairwise Data
More Hexbin Plot examples
☕