Scatter Plot

Density Scatter

Hexbin density visualization with overlaid scatter points.

Output
Density Scatter
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

# === DATA ===
np.random.seed(42)
x = np.concatenate([np.random.normal(3, 1, 200), np.random.normal(7, 1.5, 300)])
y = np.concatenate([np.random.normal(3, 1, 200), np.random.normal(6, 1.5, 300)])

# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

# === PLOT ===
# Hexbin for density
hb = ax.hexbin(x, y, gridsize=20, cmap='YlOrRd', mincnt=1, alpha=0.9)

# Outline points
ax.scatter(x, y, s=8, c='#1E293B', alpha=0.15, zorder=2)

# Colorbar
cbar = plt.colorbar(hb, ax=ax, shrink=0.8, aspect=20, pad=0.02)
cbar.ax.tick_params(labelsize=8, colors=COLORS['text_muted'])
cbar.set_label('Density', fontsize=9, color=COLORS['text_muted'])
cbar.outline.set_visible(False)

# === STYLING ===
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_color(COLORS['grid'])
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)

ax.set_xlabel('Variable X', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Variable Y', fontsize=10, color=COLORS['text'], labelpad=10)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support