2D Histogram
Revenue vs Marketing Spend
2D histogram showing company revenue correlation with marketing investment.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(42)
# Business metrics data
marketing = np.random.exponential(50000, 4000)
revenue = marketing * (3 + np.random.normal(0, 0.5, 4000)) + np.random.exponential(20000, 4000)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#020B14')
ax.set_facecolor('#020B14')
# Custom colormap: purple to amber
colors = ['#020B14', '#1a0d2e', '#4927F5', '#F5B027']
cmap = LinearSegmentedColormap.from_list('purple_amber', colors, N=256)
h = ax.hist2d(marketing/1000, revenue/1000, bins=45, cmap=cmap, cmin=1)
cbar = plt.colorbar(h[3], ax=ax, pad=0.02)
cbar.set_label('Companies', 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('Marketing Spend ($K)', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Revenue ($K)', fontsize=11, color='white', fontweight='500')
ax.set_title('Revenue vs Marketing Spend', 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
☕