Line & Scatter
Density Heatmap Scatter
Scatter plot with color intensity based on point density.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'background': '#0F172A',
'text': '#E2E8F0',
'grid': '#334155',
}
# === DATA ===
np.random.seed(42)
n = 200
# Cluster 1
x1 = np.random.normal(3, 0.8, n//2)
y1 = np.random.normal(5, 0.8, n//2)
# Cluster 2
x2 = np.random.normal(7, 1.0, n//2)
y2 = np.random.normal(3, 1.0, n//2)
x = np.concatenate([x1, x2])
y = np.concatenate([y1, y2])
# Calculate density (distance to nearest neighbors)
from scipy.spatial import distance
coords = np.column_stack([x, y])
dists = distance.cdist(coords, coords)
np.fill_diagonal(dists, np.inf)
density = 1 / (np.min(dists, axis=1) + 0.1)
density = (density - density.min()) / (density.max() - density.min())
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
# Glow based on density
for xi, yi, d in zip(x, y, density):
color = plt.cm.plasma(0.2 + 0.7 * d)
for s, alpha in [(150 * d + 50, 0.1), (80 * d + 30, 0.2)]:
ax.scatter([xi], [yi], s=s, color=color, alpha=alpha)
# Main points
scatter = ax.scatter(x, y, c=density, cmap='plasma', s=30,
edgecolors='white', linewidths=0.5, vmin=0, vmax=1)
# === AXES ===
ax.set_xlim(0, 10)
ax.set_ylim(0, 8)
ax.set_xlabel('X', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Y', fontsize=10, color=COLORS['text'], labelpad=10)
# === STYLING ===
for spine in ax.spines.values():
spine.set_visible(False)
ax.tick_params(axis='both', colors=COLORS['text'], labelsize=9, length=0, pad=8)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Line & Scatter examples
☕