Histogram
Before After Mirror
Metric comparison pyramid.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {'before': '#64748B', 'after': '#6366F1', 'background': '#FFFFFF', 'text': '#1E293B', 'text_muted': '#64748B', 'grid': '#F1F5F9'}
np.random.seed(42)
before = np.random.normal(40, 10, 300)
after = np.random.normal(55, 12, 300)
bins = np.linspace(10, 90, 20)
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
counts_b, _ = np.histogram(before, bins=bins)
counts_a, _ = np.histogram(after, bins=bins)
bin_centers = (bins[:-1] + bins[1:]) / 2
ax.barh(bin_centers, -counts_b, height=3.5, color=COLORS['before'], label='Before')
ax.barh(bin_centers, counts_a, height=3.5, color=COLORS['after'], label='After')
ax.axvline(0, color=COLORS['text'], linewidth=1)
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=9, length=0, pad=8)
ax.set_xlabel('Count', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Value', fontsize=10, color=COLORS['text'], labelpad=10)
ax.legend(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
Basic Charts
More Histogram examples
☕