2D Histogram

Coffee Consumption vs Productivity

2D histogram of daily coffee intake versus productivity scores.

Output
Coffee Consumption vs Productivity
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(42)

# Productivity study
coffee = np.clip(np.random.normal(3, 1.5, 4000), 0, 8)
productivity = 50 + coffee * 8 - (coffee - 3)**2 * 2 + np.random.normal(0, 10, 4000)
productivity = np.clip(productivity, 20, 100)

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

# Custom colormap: dark brown to amber
colors = ['#020B14', '#2d1a0d', '#9C2007', '#F5B027']
cmap = LinearSegmentedColormap.from_list('coffee', colors, N=256)

h = ax.hist2d(coffee, productivity, bins=40, cmap=cmap, cmin=1)
cbar = plt.colorbar(h[3], ax=ax, pad=0.02)
cbar.set_label('Days', 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('Coffee Cups/Day', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Productivity Score', fontsize=11, color='white', fontweight='500')
ax.set_title('Coffee Consumption vs Productivity', 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