Histogram

Multi-Group Histogram

Side-by-side group comparison.

Output
Multi-Group Histogram
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {'g1': '#6366F1', 'g2': '#10B981', 'g3': '#F59E0B', 'background': '#FFFFFF', 'text': '#1E293B', 'text_muted': '#64748B', 'grid': '#F1F5F9'}

np.random.seed(42)
g1 = np.random.normal(45, 8, 300)
g2 = np.random.normal(50, 10, 300) 
g3 = np.random.normal(55, 12, 300)

fig, axes = plt.subplots(1, 3, figsize=(12, 4), dpi=100, sharey=True)
fig.patch.set_facecolor(COLORS['background'])

for ax, data, color, label in zip(axes, [g1, g2, g3], 
                                   [COLORS['g1'], COLORS['g2'], COLORS['g3']], 
                                   ['Group A', 'Group B', 'Group C']):
    ax.set_facecolor(COLORS['background'])
    ax.hist(data, bins=20, color=color, edgecolor='white', linewidth=0.5, alpha=0.8)
    ax.axvline(np.mean(data), color=color, linewidth=2, linestyle='--')
    ax.set_title(label, fontsize=11, fontweight='bold', color=color, pad=10)
    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)
    ax.set_xlabel('Value', fontsize=9, color=COLORS['text'])

axes[0].set_ylabel('Count', fontsize=10, color=COLORS['text'])

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support