2D Histogram

Social Media Engagement Map

2D histogram of likes vs shares distribution on social media posts.

Output
Social Media Engagement Map
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(42)

# Social media engagement data
likes = np.concatenate([
    np.random.exponential(500, 3000),
    np.random.normal(2000, 300, 1000)
])
shares = likes * (0.1 + 0.05 * np.random.randn(len(likes))) + np.random.exponential(50, len(likes))
shares = np.clip(shares, 0, None)

fig, ax = plt.subplots(figsize=(10, 8), facecolor='#020B14')
ax.set_facecolor('#020B14')

# Custom colormap: coral to yellow
colors = ['#020B14', '#3d1a2e', '#F5276C', '#F5B027', '#F5D327']
cmap = LinearSegmentedColormap.from_list('coral_yellow', colors, N=256)

h = ax.hist2d(likes, shares, bins=50, cmap=cmap, cmin=1)
cbar = plt.colorbar(h[3], ax=ax, pad=0.02)
cbar.set_label('Post Count', color='white', fontsize=11)
cbar.ax.yaxis.set_tick_params(color='white')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='white')

ax.set_xlabel('Likes', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Shares', fontsize=11, color='white', fontweight='500')
ax.set_title('Social Media Engagement Map', fontsize=14, color='white', fontweight='bold', pad=15)

ax.tick_params(colors='white', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support