Bubble Chart
Automotive Comparison Bubble
Vehicles compared by horsepower, fuel efficiency, and price.
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')
cars = ['Tesla M3', 'BMW 3', 'Porsche 911', 'Camry', 'Civic', 'F-150', 'Corvette', 'Prius']
hp = np.array([283, 255, 379, 203, 180, 400, 490, 121])
mpg = np.array([132, 30, 20, 32, 36, 22, 19, 57])
price = np.array([43, 45, 115, 28, 25, 55, 65, 28])
colors = ['#F54927', '#276CF5', '#F5B027', '#6CF527', '#27D3F5', '#4927F5', '#C82909', '#27F5B0']
sizes = price * 15
for glow_mult, glow_alpha in [(2.0, 0.03), (1.6, 0.05), (1.3, 0.08)]:
ax.scatter(hp, mpg, s=sizes*glow_mult, c='#000000', alpha=glow_alpha, edgecolors='none')
ax.scatter(hp, mpg, s=sizes, c=colors, alpha=0.85, edgecolors='white', linewidth=2)
ax.scatter(hp - np.sqrt(sizes)*0.5, mpg + np.sqrt(sizes)*0.12, s=sizes*0.2, c='white', alpha=0.6, edgecolors='none')
for i, car in enumerate(cars):
offset_y = np.sqrt(sizes[i])/2 + 10
ax.annotate(car, (hp[i], mpg[i]), fontsize=10, color='#1f2937',
ha='center', va='bottom', xytext=(0, offset_y), textcoords='offset points', fontweight='bold')
ax.text(0.0, 1.08, 'Automotive Comparison', transform=ax.transAxes, fontsize=24, color='#1f2937', fontweight='bold')
ax.text(0.0, 1.02, 'Horsepower vs MPG · Bubble size = Price', transform=ax.transAxes, fontsize=11, color='#6b7280')
ax.set_xlabel('Horsepower', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.set_ylabel('MPG (or MPGe)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.tick_params(colors='#6b7280', labelsize=11, length=0)
for y in [0, 50, 100, 150]:
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
☕