Hexbin Plot

Credit Score Income

Financial hexbin showing credit score vs annual income distribution

Output
Credit Score Income
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(888)
income = np.random.lognormal(10.5, 0.6, 6000)
credit = 500 + 100 * np.log(income/10000) + np.random.normal(0, 50, 6000)
credit = np.clip(credit, 300, 850)

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

colors = ['#fef3c7', '#fde68a', '#fcd34d', '#fbbf24', '#f59e0b', '#d97706', '#b45309', '#92400e']
cmap = LinearSegmentedColormap.from_list('gold', colors, N=256)

hb = ax.hexbin(income/1000, credit, 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('#fde68a')
cbar.ax.tick_params(colors='#b45309', labelsize=9)
cbar.set_label('Applicants', color='#b45309', fontsize=10)

ax.set_xlabel('Annual Income ($K)', color='#b45309', fontsize=11)
ax.set_ylabel('Credit Score', color='#b45309', fontsize=11)
ax.tick_params(colors='#b45309', labelsize=10)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#fde68a')
ax.spines['bottom'].set_color('#fde68a')

plt.tight_layout()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support