Heatmap
A/B Test Results Matrix
Experiment variants performance across metrics
Output
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(42)
# Variants and metrics
variants = ['Control', 'Variant A', 'Variant B', 'Variant C', 'Variant D']
metrics = ['CTR', 'Conv Rate', 'AOV', 'Bounce Rate', 'Time on Site', 'Pages/Session']
# Lift vs control (%)
lift = np.zeros((len(variants), len(metrics)))
lift[0, :] = 0 # Control baseline
lift[1, :] = [5.2, 8.1, -2.3, -12.5, 15.2, 10.1] # Variant A
lift[2, :] = [2.1, 3.5, 12.4, 5.2, -3.1, 2.5] # Variant B
lift[3, :] = [-3.2, -1.5, 5.2, 8.1, -8.5, -5.2] # Variant C
lift[4, :] = [12.5, 15.2, 8.1, -18.2, 22.1, 18.5] # Variant D (winner)
df = pd.DataFrame(lift, index=variants, columns=metrics)
# Diverging colormap (red negative, green positive)
neon_div = LinearSegmentedColormap.from_list('neon_div', ['#F5276C', '#ffffff', '#6CF527'])
fig, ax = plt.subplots(figsize=(10, 5), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
# Format annotations with + for positive
def fmt_pct(x):
return f'+{x:.1f}%' if x > 0 else f'{x:.1f}%'
annot = df.applymap(fmt_pct).values
sns.heatmap(df, cmap=neon_div, center=0, annot=annot, fmt='',
linewidths=2, linecolor='#ffffff',
annot_kws={'size': 11, 'fontweight': '600'},
cbar_kws={'shrink': 0.8, 'label': 'Lift vs Control (%)'}, ax=ax)
ax.set_title('A/B Test Results Summary', color='#1f2937', fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Metric', color='#1f2937', fontsize=11)
ax.set_ylabel('Variant', color='#1f2937', fontsize=11)
ax.tick_params(colors='#374151', labelsize=10)
ax.set_xticklabels(ax.get_xticklabels(), rotation=30, ha='right')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Heatmaps & Density
More Heatmap examples
☕