2D Histogram

Property Price vs Size

2D histogram of real estate prices versus property square footage.

Output
Property Price vs Size
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(42)

# Real estate data
size = np.concatenate([
    np.random.normal(1200, 300, 2000),
    np.random.normal(2000, 400, 2500),
    np.random.normal(3500, 600, 1000)
])
size = np.clip(size, 500, 6000)
price = size * 200 + np.random.normal(0, 50000, len(size))
price = np.clip(price, 100000, 1500000)

fig, ax = plt.subplots(figsize=(10, 8), facecolor='#020B14')
ax.set_facecolor('#020B14')

# Custom colormap: mint to yellow
colors = ['#020B14', '#0d2d2d', '#27F5B0', '#F5D327']
cmap = LinearSegmentedColormap.from_list('mint_yellow', colors, N=256)

h = ax.hist2d(size, price/1000, bins=45, cmap=cmap, cmin=1)
cbar = plt.colorbar(h[3], ax=ax, pad=0.02)
cbar.set_label('Properties', color='white', fontsize=11)
cbar.ax.yaxis.set_tick_params(color='white')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='white')

ax.set_xlabel('Size (sq ft)', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Price ($K)', fontsize=11, color='white', fontweight='500')
ax.set_title('Property Price vs Size', fontsize=14, color='white', fontweight='bold', pad=15)

ax.tick_params(colors='white', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support