Heatmap

Weekly Activity Pattern

Hour-by-day activity heatmap with time patterns

Output
Weekly Activity Pattern
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(42)

# Activity by hour and day
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
hours = [f'{h:02d}:00' for h in range(24)]

# Create realistic activity pattern
activity = np.zeros((24, 7))
for h in range(24):
    for d in range(7):
        base = 20
        # Morning peak (weekdays)
        if 7 <= h <= 9 and d < 5:
            base += 60
        # Lunch peak
        if 12 <= h <= 13:
            base += 40
        # Evening peak
        if 18 <= h <= 21:
            base += 50 if d >= 5 else 30
        # Night low
        if h < 6 or h > 22:
            base = 5
        activity[h, d] = base + np.random.randint(-10, 15)

df = pd.DataFrame(activity, index=hours, columns=days)

# NEON mint colormap for light theme
neon_mint = LinearSegmentedColormap.from_list('neon_mint', ['#ffffff', '#27F5B0', '#6CF527', '#F5B027'])

fig, ax = plt.subplots(figsize=(8, 9), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

sns.heatmap(df, cmap=neon_mint, linewidths=1, linecolor='#ffffff',
            cbar_kws={'shrink': 0.5, 'label': 'Activity Level'}, ax=ax)

ax.set_title('Weekly Activity Pattern', color='#1f2937', fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Day', color='#1f2937', fontsize=11)
ax.set_ylabel('Hour', color='#1f2937', fontsize=11)
ax.tick_params(colors='#374151', labelsize=9)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Heatmaps & Density

Did this help you?

Support PyLucid to keep it free & growing

Support