Area Chart
Mirror Demographic Area
Male vs female distribution mirrored.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Data - Population pyramid
ages = ['0-9', '10-19', '20-29', '30-39', '40-49', '50-59', '60-69', '70-79', '80+']
male = [-5.2, -5.8, -6.5, -7.2, -6.8, -6.2, -5.0, -3.5, -1.8]
female = [5.0, 5.5, 6.2, 7.0, 6.6, 6.0, 5.2, 4.0, 2.5]
y = np.arange(len(ages))
# Figure - LIGHT THEME
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
# Mirrored bars as areas
ax.barh(y, male, height=0.8, color='#27D3F5', alpha=0.8, label='Male')
ax.barh(y, female, height=0.8, color='#F5276C', alpha=0.8, label='Female')
# Center line
ax.axvline(0, color='#374151', linewidth=1)
# Styling
ax.set_yticks(y)
ax.set_yticklabels(ages)
ax.set_xlabel('Population (%)', color='#1f2937', fontsize=11)
ax.set_ylabel('Age Group', color='#1f2937', fontsize=11)
ax.set_title('Population Pyramid', color='#1f2937', fontsize=14, fontweight='bold', pad=15)
ax.tick_params(colors='#374151', labelsize=9)
for spine in ax.spines.values():
spine.set_color('#e5e7eb')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.xaxis.grid(True, color='#f3f4f6', linewidth=0.5)
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', labelcolor='#1f2937', loc='lower right')
# Custom x-ticks (absolute values)
ticks = ax.get_xticks()
ax.set_xticklabels([f'{abs(int(t))}%' for t in ticks])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Area Chart examples
☕