Hexbin Plot

Real Estate Price Distribution

Property size vs price density analysis for urban housing market.

Output
Real Estate Price Distribution
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

# Real estate data
np.random.seed(42)
n_properties = 10000

# Square footage and price
sqft = np.random.lognormal(7, 0.4, n_properties)
sqft = np.clip(sqft, 500, 5000)

price_per_sqft = np.random.normal(350, 80, n_properties)
price = sqft * price_per_sqft / 1000  # in thousands
price = np.clip(price, 100, 2000)

# Modern light theme with warm tones
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#ffffff')
ax.set_facecolor('#fffbf7')

# Warm coral colormap
colors = ['#fffbf7', '#fff0e6', '#ffe0cc', '#ffc9a8', '#ffb085', 
          '#ff9666', '#f47c4a', '#e05a30', '#c43d1a', '#9a2508']
cmap = LinearSegmentedColormap.from_list('warm_coral', colors, N=256)

# Hexbin plot
hb = ax.hexbin(sqft, price, gridsize=40, cmap=cmap, mincnt=1,
               edgecolors='white', linewidths=0.4)

# Trend line
z = np.polyfit(sqft, price, 1)
p = np.poly1d(z)
x_line = np.linspace(500, 5000, 100)
ax.plot(x_line, p(x_line), '-', color='#c43d1a', linewidth=2.5, alpha=0.8, label='Market Trend')

# Styled colorbar
cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.85)
cbar.set_label('Property Count', fontsize=11, color='#44403c', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#78716c')
cbar.outline.set_edgecolor('#e7e5e4')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#78716c', fontsize=9)

# Labels
ax.set_xlabel('Square Footage', fontsize=12, color='#44403c', fontweight='600', labelpad=12)
ax.set_ylabel('Price ($K)', fontsize=12, color='#44403c', fontweight='600', labelpad=12)
ax.set_title('Real Estate Price Distribution', fontsize=16, color='#1c1917', 
             fontweight='700', pad=20)

# Clean axes
ax.tick_params(colors='#78716c', labelsize=10, length=0)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#e7e5e4')
ax.spines['bottom'].set_color('#e7e5e4')

ax.legend(loc='upper left', fontsize=10, frameon=True, facecolor='white', 
          edgecolor='#e7e5e4', labelcolor='#44403c')
ax.grid(True, alpha=0.3, color='#e7e5e4', linestyle='-', linewidth=0.5)
ax.set_axisbelow(True)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support