Heatmap

Monthly Revenue by Department

Seamless heatmap showing revenue distribution across departments and months

Output
Monthly Revenue by Department
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

fig, ax = plt.subplots(figsize=(14, 7), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

np.random.seed(42)
departments = ['Sales', 'Marketing', 'Engineering', 'Support', 'Operations']
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
data = np.random.randint(100, 800, (len(departments), len(months)))

# Modern gradient: Sky Blue to Indigo
colors = ['#e0f2fe', '#7dd3fc', '#38bdf8', '#0284c7', '#075985']
cmap = LinearSegmentedColormap.from_list('modern', colors, N=256)

im = ax.imshow(data, cmap=cmap, aspect='auto')

ax.set_xticks(range(len(months)))
ax.set_yticks(range(len(departments)))
ax.set_xticklabels(months, color='#374151', fontsize=10)
ax.set_yticklabels(departments, color='#1f2937', fontsize=10, fontweight='500')

for i in range(len(departments)):
    for j in range(len(months)):
        val = data[i, j]
        color = '#ffffff' if val > 500 else '#1f2937'
        ax.text(j, i, f'{val}', ha='center', va='center', color=color, fontsize=8, fontweight='500')

cbar = plt.colorbar(im, ax=ax, shrink=0.8, pad=0.02)
cbar.set_label('Revenue ($K)', color='#1f2937', fontsize=11)
cbar.outline.set_edgecolor('#e5e7eb')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#6b7280')

for spine in ax.spines.values():
    spine.set_color('#e5e7eb')
ax.set_xlabel('Month', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Monthly Revenue by Department', fontsize=16, color='#111827', fontweight='bold', pad=15)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Heatmaps & Density

Did this help you?

Support PyLucid to keep it free & growing

Support