Bubble Chart

Real Estate Markets Bubble

Housing markets by median price, price per sqft, and inventory.

Output
Real Estate Markets Bubble
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 = ['San Francisco', 'NYC', 'Austin', 'Miami', 'Seattle', 'Denver', 'Phoenix', 'Nashville']
median_price = np.array([1350, 850, 580, 620, 780, 620, 450, 520])
price_sqft = np.array([1100, 1450, 350, 580, 620, 380, 280, 320])
inventory = np.array([1.8, 2.5, 2.2, 1.5, 1.9, 1.4, 3.2, 2.1])

colors = ['#F5276C', '#276CF5', '#6CF527', '#27D3F5', '#4927F5', '#F5B027', '#F54927', '#27F5B0']
sizes = inventory * 300

for glow_mult, glow_alpha in [(2.0, 0.03), (1.6, 0.05), (1.3, 0.08)]:
    ax.scatter(median_price, price_sqft, s=sizes*glow_mult, c='#000000', alpha=glow_alpha, edgecolors='none')

ax.scatter(median_price, price_sqft, s=sizes, c=colors, alpha=0.85, edgecolors='white', linewidth=2)
ax.scatter(median_price - np.sqrt(sizes)*0.8, price_sqft + np.sqrt(sizes)*1.2, 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, (median_price[i], price_sqft[i]), fontsize=9, color='#1f2937',
                ha='center', va='bottom', xytext=(0, offset_y), textcoords='offset points', fontweight='bold')

ax.text(0.0, 1.08, 'Real Estate Markets', transform=ax.transAxes, fontsize=24, color='#1f2937', fontweight='bold')
ax.text(0.0, 1.02, 'Median Price vs Price/Sqft · Bubble size = Inventory', transform=ax.transAxes, fontsize=11, color='#6b7280')

ax.set_xlabel('Median Price ($K)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.set_ylabel('Price per Sq Ft ($)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.tick_params(colors='#6b7280', labelsize=11, length=0)

for y in [0, 500, 1000, 1500]:
    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

Did this help you?

Support PyLucid to keep it free & growing

Support