Bubble Chart
Air Quality Index Bubble
Global cities by pollution levels, density, and green space.
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')
cities = ['Delhi', 'Beijing', 'Los Angeles', 'London', 'Tokyo', 'Sydney', 'Copenhagen', 'Singapore']
pm25 = np.array([125, 85, 35, 28, 22, 12, 10, 18])
density = np.array([11, 5.5, 3.3, 5.7, 6.3, 0.4, 7.4, 8.3])
green = np.array([5, 12, 15, 33, 28, 46, 35, 30])
colors = ['#C82909', '#F54927', '#F5B027', '#276CF5', '#27D3F5', '#6CF527', '#27F5B0', '#4927F5']
sizes = green * 30
for glow_mult, glow_alpha in [(2.0, 0.03), (1.6, 0.05), (1.3, 0.08)]:
ax.scatter(pm25, density, s=sizes*glow_mult, c='#000000', alpha=glow_alpha, edgecolors='none')
ax.scatter(pm25, density, s=sizes, c=colors, alpha=0.85, edgecolors='white', linewidth=2)
ax.scatter(pm25 - np.sqrt(sizes)*0.15, density + np.sqrt(sizes)*0.015, s=sizes*0.2, c='white', alpha=0.6, edgecolors='none')
for i, city in enumerate(cities):
offset_y = np.sqrt(sizes[i])/2 + 10
ax.annotate(city, (pm25[i], density[i]), fontsize=10, color='#1f2937',
ha='center', va='bottom', xytext=(0, offset_y), textcoords='offset points', fontweight='bold')
ax.text(0.0, 1.08, 'Air Quality Index', transform=ax.transAxes, fontsize=24, color='#1f2937', fontweight='bold')
ax.text(0.0, 1.02, 'PM2.5 vs Density · Bubble size = Green Space', transform=ax.transAxes, fontsize=11, color='#6b7280')
ax.set_xlabel('PM2.5 Level (μg/m³)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.set_ylabel('Population Density (K/km²)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.tick_params(colors='#6b7280', labelsize=11, length=0)
for y in [0, 3, 6, 9, 12]:
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
☕