Calendar Heatmap

GitHub Contributions Calendar

GitHub-style contribution calendar showing daily commit activity throughout the year.

Output
GitHub Contributions Calendar
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.patches as mpatches

np.random.seed(42)

# Generate 365 days of contribution data
days = 365
contributions = np.random.exponential(2, days).astype(int)
contributions = np.clip(contributions, 0, 15)
# Add some zero days for realism
contributions[np.random.choice(days, size=80, replace=False)] = 0

# Reshape into weeks (52 weeks x 7 days)
weeks = 53
data = np.zeros((7, weeks))
for i, val in enumerate(contributions):
    week = i // 7
    day = i % 7
    if week < weeks:
        data[day, week] = val

# Custom GitHub-style colormap
colors_dark = ['#0a0a0f', '#0e4429', '#006d32', '#26a641', '#39d353']
cmap = LinearSegmentedColormap.from_list('github', colors_dark, N=256)

fig, ax = plt.subplots(figsize=(16, 4), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

# Create heatmap
im = ax.imshow(data, cmap=cmap, aspect='auto', vmin=0, vmax=15)

# Style
ax.set_yticks(range(7))
ax.set_yticklabels(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], fontsize=9, color='#e2e8f0')
ax.set_xticks(range(0, 52, 4))
ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ''], 
                   fontsize=9, color='#e2e8f0')

ax.set_title('GitHub Contributions - 2024', fontsize=16, color='white', fontweight='bold', pad=15)

# Add grid lines between cells
for i in range(8):
    ax.axhline(y=i-0.5, color='#1e293b', linewidth=0.5)
for i in range(weeks+1):
    ax.axvline(x=i-0.5, color='#1e293b', linewidth=0.5)

ax.tick_params(colors='#e2e8f0', length=0)
for spine in ax.spines.values():
    spine.set_visible(False)

# Legend
legend_elements = [mpatches.Patch(facecolor=c, label=l, edgecolor='#334155') 
                   for c, l in zip(colors_dark, ['None', 'Low', 'Medium', 'High', 'Very High'])]
ax.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, -0.15), ncol=5, 
          fontsize=8, facecolor='#1e293b', edgecolor='#334155', labelcolor='white', title='Activity Level',
          title_fontsize=9)

# Stats annotation
total = int(np.sum(contributions))
ax.annotate(f'{total} contributions in the last year', xy=(0.98, 1.1), xycoords='axes fraction',
            fontsize=11, color='#6CF527', ha='right', fontweight='bold')

plt.tight_layout()
plt.subplots_adjust(bottom=0.25)
plt.show()
Library

Matplotlib

Category

Time Series

Did this help you?

Support PyLucid to keep it free & growing

Support