Line & Scatter

Conversion Funnel

Funnel stages with conversion rates and drop-off analysis.

Output
Conversion Funnel
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'funnel': '#3B82F6',
    'dropoff': '#EF4444',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

# === DATA ===
stages = ['Visitors', 'Sign-ups', 'Activated', 'Subscribed', 'Retained']
values = [10000, 3200, 1800, 720, 540]
x = np.arange(len(stages))

# Calculate conversion rates
conversions = [100]
for i in range(1, len(values)):
    conversions.append(values[i] / values[i-1] * 100)

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

# === PLOT ===
# Main line
ax.plot(x, values, color=COLORS['funnel'], linewidth=3, zorder=3)

# Fill area
ax.fill_between(x, 0, values, color=COLORS['funnel'], alpha=0.1)

# Points with size based on value
sizes = [v/50 for v in values]
ax.scatter(x, values, s=sizes, color=COLORS['funnel'], 
           edgecolors='white', linewidths=2, zorder=4)

# Value labels
for i, (xi, v, conv) in enumerate(zip(x, values, conversions)):
    # Value
    ax.annotate(f'{v:,}', xy=(xi, v), xytext=(0, 15),
                textcoords='offset points', ha='center',
                fontsize=11, fontweight='bold', color=COLORS['text'])
    # Conversion rate
    if i > 0:
        color = COLORS['funnel'] if conv > 40 else COLORS['dropoff']
        ax.annotate(f'{conv:.0f}%', xy=(xi - 0.5, (values[i-1] + v) / 2),
                    fontsize=9, ha='center', color=color)

# Drop-off visualization
for i in range(len(x) - 1):
    ax.annotate('', xy=(x[i+1], values[i+1]), xytext=(x[i], values[i]),
                arrowprops=dict(arrowstyle='->', color=COLORS['text_muted'],
                               lw=1, connectionstyle='arc3,rad=-0.1'))

# === AXES ===
ax.set_xlim(-0.5, len(stages) - 0.5)
ax.set_ylim(0, 12000)
ax.set_xticks(x)
ax.set_xticklabels(stages)
ax.set_ylabel('Users', fontsize=10, color=COLORS['text'], labelpad=10)

# === 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)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support