Bubble Chart
World Health Indicators
Countries compared by life expectancy, GDP per capita, and population with modern styling.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
fig, ax = plt.subplots(figsize=(14, 9), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
countries = ['Japan', 'USA', 'Germany', 'Brazil', 'India', 'Nigeria', 'Australia', 'China']
life_exp = np.array([84.5, 78.9, 81.3, 75.9, 70.4, 54.7, 83.4, 78.2])
gdp_pc = np.array([42, 76, 51, 9, 2.4, 2.2, 60, 13])
population = np.array([125, 335, 84, 216, 1420, 220, 26, 1410])
colors = ['#F54927', '#276CF5', '#F5B027', '#6CF527', '#F5276C', '#27D3F5', '#4927F5', '#C82909']
sizes = population / 2
# Soft shadow effect for light theme
for glow_mult, glow_alpha in [(2.0, 0.03), (1.6, 0.05), (1.3, 0.08)]:
ax.scatter(gdp_pc, life_exp, s=sizes*glow_mult, c='#000000', alpha=glow_alpha, edgecolors='none')
ax.scatter(gdp_pc, life_exp, s=sizes, c=colors, alpha=0.85, edgecolors='white', linewidth=2)
ax.scatter(gdp_pc - np.sqrt(sizes)*0.08, life_exp + np.sqrt(sizes)*0.012, s=sizes*0.2, c='white', alpha=0.6, edgecolors='none')
for i, country in enumerate(countries):
offset_y = np.sqrt(sizes[i])/2 + 12
ax.annotate(country, (gdp_pc[i], life_exp[i]), fontsize=11, color='#1f2937',
ha='center', va='bottom', xytext=(0, offset_y), textcoords='offset points', fontweight='bold')
ax.text(0.0, 1.08, 'World Health Indicators', transform=ax.transAxes, fontsize=24, color='#1f2937', fontweight='bold')
ax.text(0.0, 1.02, 'GDP per Capita vs Life Expectancy · Bubble size = Population', transform=ax.transAxes, fontsize=11, color='#6b7280')
ax.set_xlabel('GDP per Capita ($K)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.set_ylabel('Life Expectancy (Years)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.tick_params(colors='#6b7280', labelsize=11, length=0)
for y in [50, 60, 70, 80, 90]:
ax.axhline(y=y, color='#f3f4f6', linewidth=1, zorder=0)
for spine in ax.spines.values():
spine.set_visible(False)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Bubble Chart examples
☕