Scatter Plot

Multi-Group Regression

Comparing linear trends across three product categories.

Output
Multi-Group Regression
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'group1': '#3B82F6',
    'group2': '#10B981',
    'group3': '#F59E0B',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

# === DATA ===
np.random.seed(42)
x = np.linspace(1, 10, 30)
y1 = 2.5 * x + 5 + np.random.normal(0, 2, 30)
y2 = 1.8 * x + 12 + np.random.normal(0, 2, 30)
y3 = 3.2 * x + 0 + np.random.normal(0, 2, 30)

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

# === PLOT ===
for yi, color, label in [(y1, COLORS['group1'], 'Product A'),
                          (y2, COLORS['group2'], 'Product B'),
                          (y3, COLORS['group3'], 'Product C')]:
    # Trend line
    z = np.polyfit(x, yi, 1)
    p = np.poly1d(z)
    ax.plot(x, p(x), color=color, linewidth=5, alpha=0.15, zorder=1)
    ax.plot(x, p(x), color=color, linewidth=2, zorder=2)
    
    # Points with glow
    ax.scatter(x, yi, s=100, c=color, alpha=0.15, zorder=3)
    ax.scatter(x, yi, s=40, c=color, alpha=0.8,
               edgecolors='white', linewidths=1.5, label=label, 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_xlabel('Time Period', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Revenue ($K)', fontsize=10, color=COLORS['text'], labelpad=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