Scatter Plot

Cluster Scatter

Three distinct clusters with glow effect using k-means-style grouping.

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

# === STYLE CONFIG ===
COLORS = {
    'cluster1': '#6366F1',
    'cluster2': '#10B981', 
    'cluster3': '#F59E0B',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

# === DATA ===
np.random.seed(42)
# Three clusters
c1_x, c1_y = np.random.normal(3, 0.8, 25), np.random.normal(7, 0.8, 25)
c2_x, c2_y = np.random.normal(7, 1, 30), np.random.normal(3, 1, 30)
c3_x, c3_y = np.random.normal(5, 0.6, 20), np.random.normal(5, 0.6, 20)

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

# === PLOT ===
for x, y, color, label in [
    (c1_x, c1_y, COLORS['cluster1'], 'Cluster A'),
    (c2_x, c2_y, COLORS['cluster2'], 'Cluster B'),
    (c3_x, c3_y, COLORS['cluster3'], 'Cluster C'),
]:
    # Glow
    ax.scatter(x, y, s=200, c=color, alpha=0.1, zorder=1)
    # Points
    ax.scatter(x, y, s=80, c=color, alpha=0.8, 
               edgecolors='white', linewidths=1.5, label=label, zorder=3)

# === 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.yaxis.grid(True, color=COLORS['grid'], linewidth=1)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)

ax.set_xlim(0, 10)
ax.set_ylim(0, 10)

ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
          ncol=3, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support