Bubble Chart
Global Megacities Bubble
World megacities compared by GDP, population, and urban density with neon visualization.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
fig, ax = plt.subplots(figsize=(14, 9), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
cities = ['Tokyo', 'NYC', 'London', 'Shanghai', 'Singapore', 'Dubai', 'Sydney', 'Seoul']
gdp = np.array([1900, 1700, 1100, 810, 400, 110, 400, 950])
population = np.array([37, 18, 14, 28, 6, 3.5, 5.3, 25])
area = np.array([2194, 783, 1572, 6341, 733, 4114, 12367, 605])
colors = ['#F54927', '#27D3F5', '#F5276C', '#F5B027', '#6CF527', '#4927F5', '#27F5B0', '#F527B0']
sizes = area / 8
for glow_mult, glow_alpha in [(3.5, 0.02), (2.8, 0.04), (2.2, 0.06), (1.7, 0.10), (1.3, 0.15)]:
ax.scatter(gdp, population, s=sizes*glow_mult, c=colors, alpha=glow_alpha, edgecolors='none')
ax.scatter(gdp, population, s=sizes, c=colors, alpha=0.9, edgecolors='none')
ax.scatter(gdp, population, s=sizes*0.4, c=colors, alpha=0.4, edgecolors='none')
ax.scatter(gdp - np.sqrt(sizes)*0.8, population + np.sqrt(sizes)*0.03, s=sizes*0.15, c='white', alpha=0.5, edgecolors='none')
for i, city in enumerate(cities):
offset_y = np.sqrt(sizes[i])/2 + 12
ax.annotate(city, (gdp[i], population[i]), fontsize=12, color='white',
ha='center', va='bottom', xytext=(0, offset_y), textcoords='offset points', fontweight='bold')
ax.text(0.0, 1.08, 'Global Megacities', transform=ax.transAxes, fontsize=24, color='white', fontweight='bold')
ax.text(0.0, 1.02, 'GDP vs Population · Bubble size = Urban Area', transform=ax.transAxes, fontsize=11, color='#555555')
ax.set_xlabel('GDP (Billion $)', fontsize=14, color='#888888', fontweight='500', labelpad=15)
ax.set_ylabel('Population (Millions)', fontsize=14, color='#888888', fontweight='500', labelpad=15)
ax.tick_params(colors='#555555', labelsize=11, length=0)
for y in [0, 10, 20, 30, 40]:
ax.axhline(y=y, color='#1a1a2e', linewidth=0.8, 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
☕