Heatmap
Attendance Heatmap
Light theme heatmap showing employee attendance patterns
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import FancyBboxPatch
fig, ax = plt.subplots(figsize=(14, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
np.random.seed(42)
employees = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve', 'Frank', 'Grace']
weeks = [f'W{i+1}' for i in range(12)]
data = np.random.choice([0, 1, 2], size=(len(employees), len(weeks)), p=[0.05, 0.15, 0.8])
colors = ['#7f1d1d', '#fbbf24', '#22c55e']
cmap = LinearSegmentedColormap.from_list('attendance', colors, N=3)
cell_w, cell_h = 0.88, 0.82
status_labels = {0: 'A', 1: 'P', 2: 'F'}
for i in range(len(employees)):
for j in range(len(weeks)):
val = data[i, j]
rect = FancyBboxPatch((j - cell_w/2, i - cell_h/2), cell_w, cell_h,
boxstyle="round,pad=0.02,rounding_size=0.12",
facecolor=cmap(val/2), edgecolor='#e2e8f0', linewidth=1.5)
ax.add_patch(rect)
ax.text(j, i, status_labels[val], ha='center', va='center', color='#1e293b', fontsize=10, fontweight='bold')
ax.set_xlim(-0.5, len(weeks)-0.5)
ax.set_ylim(-0.5, len(employees)-0.5)
ax.set_aspect('equal')
ax.invert_yaxis()
ax.set_xticks(range(len(weeks)))
ax.set_yticks(range(len(employees)))
ax.set_xticklabels(weeks, color='#64748b', fontsize=10, fontweight='500')
ax.set_yticklabels(employees, color='#1e293b', fontsize=11, fontweight='500')
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(0, 2))
cbar = plt.colorbar(sm, ax=ax, shrink=0.8, pad=0.02, ticks=[0.33, 1, 1.67])
cbar.ax.set_yticklabels(['Absent', 'Partial', 'Full'], color='#64748b')
cbar.outline.set_edgecolor('#e2e8f0')
for spine in ax.spines.values(): spine.set_visible(False)
ax.tick_params(length=0)
ax.set_title('Team Attendance Tracker', fontsize=18, color='#1e293b', fontweight='bold', pad=20)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Heatmaps & Density
More Heatmap examples
☕