Bar Chart

Pyramid Chart

Population pyramid style comparison

Output
Pyramid Chart
Python
import matplotlib.pyplot as plt
import numpy as np

age_groups = ['65+', '55-64', '45-54', '35-44', '25-34', '18-24', '<18']
male = [-12, -15, -18, -22, -25, -20, -15]
female = [14, 16, 17, 20, 23, 18, 14]

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

y_pos = np.arange(len(age_groups))

ax.barh(y_pos, male, height=0.7, color='#27D3F5', label='Male')
ax.barh(y_pos, female, height=0.7, color='#F5276C', label='Female')

for i, (m, f) in enumerate(zip(male, female)):
    ax.text(m - 1, i, f'{abs(m)}%', ha='right', va='center', color='white', fontsize=9)
    ax.text(f + 1, i, f'{f}%', ha='left', va='center', color='white', fontsize=9)

ax.axvline(x=0, color='#444444', linewidth=1)
ax.set_yticks(y_pos)
ax.set_yticklabels(age_groups, color='white', fontsize=10)
ax.set_xlim(-30, 30)
ax.set_xlabel('Population Share (%)', color='#888888', fontsize=11)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_color('#333333')
ax.tick_params(axis='x', colors='#888888', labelsize=9)
ax.tick_params(axis='y', length=0)

ax.legend(loc='upper right', frameon=False, labelcolor='white', fontsize=9)
ax.set_title('Population Distribution by Age', color='white', fontsize=14, fontweight='bold', pad=15)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support