Histogram

Small Multiples Histogram

Distribution faceted by category.

Output
Small Multiples Histogram
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {'bars': '#374151', 'mean': '#DC2626', 'background': '#FFFFFF', 'text': '#1E293B', 'text_muted': '#64748B', 'grid': '#F1F5F9'}

np.random.seed(42)
categories = ['Q1', 'Q2', 'Q3', 'Q4']
data = [np.random.normal(50 + i*5, 10, 200) for i in range(4)]

fig, axes = plt.subplots(2, 2, figsize=(10, 8), dpi=100, sharex=True, sharey=True)
fig.patch.set_facecolor(COLORS['background'])

for ax, d, cat in zip(axes.flat, data, categories):
    ax.set_facecolor(COLORS['background'])
    ax.hist(d, bins=20, color=COLORS['bars'], edgecolor='white', linewidth=0.5, alpha=0.85)
    ax.axvline(np.mean(d), color=COLORS['mean'], linewidth=2, linestyle='--')
    ax.set_title(cat, fontsize=11, fontweight='bold', color=COLORS['text'], pad=8)
    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.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=8, length=0, pad=5)

fig.text(0.5, 0.02, 'Value', ha='center', fontsize=10, color=COLORS['text'])
fig.text(0.02, 0.5, 'Count', va='center', rotation='vertical', fontsize=10, color=COLORS['text'])

plt.tight_layout(rect=[0.03, 0.03, 1, 1])
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support