Mirror Chart
A/B Test: Control vs Variant
Mirror density showing conversion rate distributions with statistical significance
Output
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde, ttest_ind
np.random.seed(789)
BG_COLOR = '#0d1117'
# Conversion rates (%)
control = np.random.beta(2.5, 22, 2000) * 100
variant = np.random.beta(3.2, 22, 2000) * 100
fig, ax = plt.subplots(figsize=(12, 7), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
x = np.linspace(0, 30, 500)
# Control (top)
kde_c = gaussian_kde(control)
y_c = kde_c(x)
ax.fill_between(x, y_c, alpha=0.15, color='#888888')
ax.plot(x, y_c, color='#888888', linewidth=4, alpha=0.3)
ax.plot(x, y_c, color='#888888', linewidth=2, label=f'Control (μ={np.mean(control):.2f}%)')
# Variant (bottom) with glow
kde_v = gaussian_kde(variant)
y_v = kde_v(x) * -1
ax.fill_between(x, y_v, alpha=0.2, color='#6CF527')
ax.plot(x, y_v, color='#6CF527', linewidth=5, alpha=0.3)
ax.plot(x, y_v, color='#6CF527', linewidth=2, label=f'Variant (μ={np.mean(variant):.2f}%)')
ax.axhline(0, color='#444444', linewidth=1.5)
# Mean lines
ax.axvline(np.mean(control), color='#888888', linestyle='--', alpha=0.6, linewidth=1.5)
ax.axvline(np.mean(variant), color='#6CF527', linestyle='--', alpha=0.6, linewidth=1.5)
# Statistical test
t_stat, p_value = ttest_ind(variant, control)
lift = ((np.mean(variant) - np.mean(control)) / np.mean(control)) * 100
sig = "✓ Significant" if p_value < 0.05 else "✗ Not Significant"
sig_color = '#6CF527' if p_value < 0.05 else '#ef4444'
# Results box
results = f"Lift: +{lift:.1f}% | p-value: {p_value:.4f} | {sig}"
ax.text(0.5, 0.98, results, transform=ax.transAxes, ha='center', va='top',
fontsize=12, color=sig_color, fontweight='bold',
bbox=dict(boxstyle='round,pad=0.5', facecolor=BG_COLOR, edgecolor=sig_color, lw=2))
# Confidence annotation
ax.annotate(f'+{lift:.1f}%', xy=(np.mean(variant), min(y_v)*0.5),
fontsize=20, color='#6CF527', fontweight='bold', ha='center')
ax.set_xlabel('Conversion Rate (%)', fontsize=12, color='white', fontweight='500')
ax.set_title('A/B Test Results: Feature Rollout', fontsize=16, color='white', fontweight='bold', pad=25)
ax.tick_params(colors='#888888', labelsize=10)
ax.set_yticks([])
for spine in ['top', 'right']:
ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
ax.spines[spine].set_color('#333333')
ax.legend(loc='upper right', facecolor=BG_COLOR, edgecolor='#333333', labelcolor='white', fontsize=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕