Scatter Plot

Marginal Distributions

Scatter with histogram distributions on margins.

Output
Marginal Distributions
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.gridspec import GridSpec

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

# === DATA ===
np.random.seed(42)
x = np.random.normal(50, 15, 200)
y = 0.8 * x + np.random.normal(0, 10, 200)

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

gs = GridSpec(4, 4, figure=fig, hspace=0.05, wspace=0.05)
ax_main = fig.add_subplot(gs[1:4, 0:3])
ax_top = fig.add_subplot(gs[0, 0:3], sharex=ax_main)
ax_right = fig.add_subplot(gs[1:4, 3], sharey=ax_main)

for ax in [ax_main, ax_top, ax_right]:
    ax.set_facecolor(COLORS['background'])

# === MAIN SCATTER ===
ax_main.scatter(x, y, s=100, c=COLORS['primary'], alpha=0.15, zorder=1)
ax_main.scatter(x, y, s=40, c=COLORS['primary'], alpha=0.7,
                edgecolors='white', linewidths=1, zorder=2)

# === MARGINAL HISTOGRAMS ===
ax_top.hist(x, bins=25, color=COLORS['primary'], alpha=0.6, edgecolor='white')
ax_right.hist(y, bins=25, color=COLORS['primary'], alpha=0.6, 
              edgecolor='white', orientation='horizontal')

# === STYLING ===
for ax in [ax_main, ax_top, ax_right]:
    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(colors=COLORS['text_muted'], labelsize=8, length=0)

ax_top.tick_params(labelbottom=False)
ax_right.tick_params(labelleft=False)

ax_main.set_xlabel('Feature X', fontsize=10, color=COLORS['text'], labelpad=10)
ax_main.set_ylabel('Feature 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