import numpy as np import matplotlib.pyplot as plt # Select the relevant columns from the DataFrame x = df['population'] y = df['median_house_value'] # Define the desired x-axis range x_max = 5000 # Create a 2D histogram-like representation heatmap, xedges, yedges = np.histogram2d(x, y, bins=50, range=[[0, x_max], [min(y), max(y)]]) extent = [0, x_max, yedges[0], yedges[-1]] # Create the heatmap using imshow plt.imshow(heatmap.T, origin='lower', extent=extent, aspect='auto', cmap=plt.cm.get_cmap('YlOrRd')) plt.colorbar(label='Frequency') plt.xlabel('Population') plt.ylabel('Median House Value') plt.title('Heatmap of Median House Value vs Population') plt.show()