Linear Regression Plot
Website Speed vs Conversion Rate
Web performance impact on business metrics
Output
Python
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
np.random.seed(407)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
n = 65
load_time = np.random.uniform(0.5, 8, n)
conversion = 8 - 0.9 * load_time + np.random.normal(0, 0.8, n)
conversion = np.clip(conversion, 0, 10)
df = pd.DataFrame({'Load Time (s)': load_time, 'Conversion Rate (%)': conversion})
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
sns.regplot(
data=df,
x='Load Time (s)',
y='Conversion Rate (%)',
scatter_kws={'color': '#F5276C', 'alpha': 0.7, 's': 55, 'edgecolor': 'white', 'linewidths': 0.5},
line_kws={'color': '#27D3F5', 'linewidth': 2.5},
ci=95,
ax=ax
)
for collection in ax.collections[1:]:
collection.set_facecolor('#27D3F5')
collection.set_alpha(0.15)
ax.axvline(2.5, color='#22c55e', linestyle='--', alpha=0.5, linewidth=1)
ax.text(2.6, 1, 'Good', color='#22c55e', fontsize=9, rotation=90)
corr = np.corrcoef(load_time, conversion)[0, 1]
ax.text(0.95, 0.95, 'r = %.3f' % corr, transform=ax.transAxes, fontsize=12,
color='#27D3F5', fontweight='bold', va='top', ha='right',
bbox=dict(boxstyle='round,pad=0.3', facecolor='#1a1a2e', edgecolor='#333'))
ax.set_xlabel('Page Load Time (seconds)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Conversion Rate (%)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Website Speed vs Conversion', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.tick_params(colors='#888', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#333')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Linear Regression Plot examples
☕