Area Chart

Social Media Post Reach

Post engagement decay over time with viral boost

Output
Social Media Post Reach
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)
hours = np.linspace(0, 72, 200)  # 72 hours

# Engagement decay with viral spike
base_reach = 1000 * np.exp(-hours/24)
viral_spike = 800 * np.exp(-((hours - 8)**2)/10)  # Viral at hour 8
total_reach = base_reach + viral_spike + np.random.normal(0, 30, len(hours))
total_reach = np.clip(total_reach, 0, None)

# Cumulative
cumulative = np.cumsum(total_reach) / 10

fig, ax1 = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax1.set_facecolor('#ffffff')

# Instantaneous reach
ax1.fill_between(hours, 0, total_reach, alpha=0.4, color='#F5276C')
ax1.plot(hours, total_reach, color='#F5276C', linewidth=2, label='Hourly reach')
ax1.set_ylabel('Hourly Reach', color='#F5276C', fontsize=11)
ax1.tick_params(axis='y', colors='#F5276C', labelsize=9)

# Cumulative on secondary axis
ax2 = ax1.twinx()
ax2.plot(hours, cumulative, color='#4927F5', linewidth=2.5, linestyle='--', label='Cumulative')
ax2.set_ylabel('Total Impressions', color='#4927F5', fontsize=11)
ax2.tick_params(axis='y', colors='#4927F5', labelsize=9)

# Viral moment annotation
ax1.annotate('Viral boost!', xy=(8, total_reach[26]), xytext=(20, 1400),
             arrowprops=dict(arrowstyle='->', color='#6CF527'),
             color='#6CF527', fontsize=10, fontweight='bold')

ax1.set_xlabel('Hours Since Post', color='#1f2937', fontsize=11)
ax1.set_title('Social Media Post Performance', color='#1f2937', fontsize=14, fontweight='bold', pad=15)
ax1.tick_params(axis='x', colors='#374151', labelsize=9)
for spine in ax1.spines.values():
    spine.set_color('#e5e7eb')
for spine in ax2.spines.values():
    spine.set_color('#e5e7eb')
ax1.set_xlim(0, 72)

# Combined legend
lines1, labels1 = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(lines1 + lines2, labels1 + labels2, loc='upper right', facecolor='#ffffff', edgecolor='#e5e7eb')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support