2D Histogram
Video Views vs Watch Time
2D histogram of video view counts versus average watch duration.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(42)
# Video analytics
views = np.random.exponential(10000, 4000)
watch_time = np.random.beta(2, 3, 4000) * 15 + 0.5 # minutes
watch_time = watch_time * (1 + np.log1p(views) * 0.05)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#020B14')
ax.set_facecolor('#020B14')
# Custom colormap: coral to cyan
colors = ['#020B14', '#2d1a2e', '#F5276C', '#27D3F5']
cmap = LinearSegmentedColormap.from_list('coral_cyan', colors, N=256)
h = ax.hist2d(np.log10(views + 1), watch_time, bins=45, cmap=cmap, cmin=1)
cbar = plt.colorbar(h[3], ax=ax, pad=0.02)
cbar.set_label('Videos', 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('Views (log10)', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Avg Watch Time (min)', fontsize=11, color='white', fontweight='500')
ax.set_title('Video Views vs Watch Time', 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
More 2D Histogram examples
☕