Linear Regression Plot
Followers vs Engagement Rate
Social media analytics and influence metrics
Output
Python
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
np.random.seed(413)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
n = 70
followers = np.random.uniform(1, 500, n)
engagement = 8 - 0.01 * followers + np.random.normal(0, 1.2, n)
engagement = np.clip(engagement, 0.5, 12)
df = pd.DataFrame({'Followers (K)': followers, 'Engagement Rate (%)': engagement})
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
sns.regplot(
data=df,
x='Followers (K)',
y='Engagement Rate (%)',
scatter_kws={'color': '#F5276C', 'alpha': 0.6, '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.axhline(3.0, color='#22c55e', linestyle='--', alpha=0.5, linewidth=1)
ax.text(480, 3.2, 'Good', color='#22c55e', fontsize=9, ha='right')
corr = np.corrcoef(followers, engagement)[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='#f8fafc', edgecolor='#e5e7eb'))
ax.set_xlabel('Followers (K)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Engagement Rate (%)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Social Media Followers vs Engagement', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#e5e7eb')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Linear Regression Plot examples
☕