Line & Scatter

Scatter with Size Encoding

Bubble scatter plot where point size represents a third variable.

Output
Scatter with Size Encoding
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'bubbles': '#06B6D4',    # Cyan
    'background': '#FAFBFC',
    'text_muted': '#64748B',
    'grid': '#E2E8F0',
}

# === DATA ===
np.random.seed(42)
n = 40
x = np.random.uniform(1, 10, n)
y = np.random.uniform(1, 10, n)
sizes = np.random.uniform(100, 800, n)  # Third variable

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

# === PLOT ===
scatter = ax.scatter(x, y, s=sizes, c=COLORS['bubbles'], alpha=0.6,
                     edgecolors='white', linewidths=1.5)

# === AXES ===
ax.set_xlim(0, 11)
ax.set_ylim(0, 11)
ax.set_xlabel('Variable X', fontsize=10, color=COLORS['text_muted'], labelpad=10)
ax.set_ylabel('Variable Y', fontsize=10, color=COLORS['text_muted'], labelpad=10)

# === STYLING ===
for spine in ['top', 'right']:
    ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
    ax.spines[spine].set_color(COLORS['grid'])

ax.yaxis.grid(True, color=COLORS['grid'], linewidth=0.5, alpha=0.7)
ax.xaxis.grid(True, color=COLORS['grid'], linewidth=0.5, alpha=0.7)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)

# Size legend
for size, label in [(200, 'Small'), (500, 'Medium'), (800, 'Large')]:
    ax.scatter([], [], s=size, c=COLORS['bubbles'], alpha=0.6,
               edgecolors='white', linewidths=1.5, label=label)

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

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support