Scatter Plot
Size-Encoded Scatter
Bubble chart with size representing a third dimension and labeled top values.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'primary': '#8B5CF6',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
# === DATA ===
np.random.seed(42)
x = np.random.uniform(1, 9, 20)
y = np.random.uniform(1, 9, 20)
values = np.random.uniform(10, 100, 20)
sizes = values * 10
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
# Glow layers
for alpha, scale in [(0.03, 2.0), (0.06, 1.5)]:
ax.scatter(x, y, s=sizes * scale, c=COLORS['primary'], alpha=alpha, zorder=1)
# Main points
scatter = ax.scatter(x, y, s=sizes, c=COLORS['primary'], alpha=0.7,
edgecolors='white', linewidths=2, zorder=3)
# Value labels for top 5
top_idx = np.argsort(values)[-5:]
for i in top_idx:
ax.annotate(f'{values[i]:.0f}', (x[i], y[i]),
ha='center', va='center', fontsize=8,
color='white', fontweight='bold', zorder=4)
# === 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.set_xlabel('Feature A', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Feature B', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Scatter Plot examples
☕