Boxplot

Daily Active Users

DAU distribution by day of week.

Output
Daily Active Users
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {'weekday': '#6366F1', 'weekend': '#10B981', 'median': '#FFFFFF', 'background': '#FFFFFF', 'text': '#1E293B', 'text_muted': '#64748B', 'grid': '#F1F5F9'}

np.random.seed(42)
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
means = [45000, 48000, 50000, 52000, 55000, 35000, 30000]
data = [np.random.normal(m, 5000, 52) for m in means]

fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

bp = ax.boxplot(data, widths=0.5, patch_artist=True, showfliers=False,
                medianprops=dict(color=COLORS['median'], linewidth=2))

colors = [COLORS['weekday']]*5 + [COLORS['weekend']]*2
for patch, color in zip(bp['boxes'], colors):
    patch.set_facecolor(color)
    patch.set_edgecolor('white')
for i, color in enumerate(colors):
    bp['whiskers'][i*2].set_color(color)
    bp['whiskers'][i*2+1].set_color(color)
    bp['caps'][i*2].set_color(color)
    bp['caps'][i*2+1].set_color(color)

ax.set_xticklabels(days)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_color(COLORS['grid'])
ax.yaxis.grid(True, color=COLORS['grid'], linewidth=1, zorder=0)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.set_ylabel('Daily Active Users', fontsize=10, color=COLORS['text'], labelpad=10)

# Add legend manually
from matplotlib.patches import Patch
legend_elements = [Patch(facecolor=COLORS['weekday'], label='Weekday'),
                   Patch(facecolor=COLORS['weekend'], label='Weekend')]
ax.legend(handles=legend_elements, loc='upper center', bbox_to_anchor=(0.5, -0.12), 
          ncol=2, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support