下面这份代码修改成可以在pycharm中显示出来的 data['persqm'] = pd.to_numeric(data['persqm'], errors='coerce') data = data.dropna(subset=['persqm']) price_level = pd.cut(data['persqm'], bins=[0, 10000, 20000, 30000, 40000, float('inf')], labels=['0-1万', '1-2万', '2-3万', '3-4万', '4万以上']) area_level = pd.cut(data['square'], bins=[0, 10, 20, 30, 40, 50, 60, 70, float('inf')], labels=['0-10', '10-20', '20-30', '30-40', '40-50', '50-60', '60-70', '70以上']) house_type = data['house_type'] direction = data['direction'] deco = data['deco'] fig, axs = plt.subplots(2, 2, figsize=(12, 8)) fig.suptitle('房价与特征之间的关系', fontsize=16) # Subplot 1: House type vs Price level axs[0, 0].scatter(house_type, price_level, alpha=0.6) axs[0, 0].set_xlabel('房型', fontsize=12) axs[0, 0].set_ylabel('每平米房价(万元)', fontsize=12) # Subplot 2: Area level vs Price level axs[0, 1].scatter(area_level, price_level, alpha=0.6) axs[0, 1].set_xlabel('房屋面积(平方米)', fontsize=12) axs[0, 1].set_ylabel('每平米房价(万元)', fontsize=12) # Subplot 3: Direction vs Price level axs[1, 0].scatter(direction, price_level, alpha=0.6) axs[1, 0].set_xlabel('朝向', fontsize=12) axs[1, 0].set_ylabel('每平米房价(万元)', fontsize=12) # Subplot 4: Decoration vs Price level axs[1, 1].scatter(deco, price_level, alpha=0.6) axs[1, 1].set_xlabel('装修情况', fontsize=12) axs[1, 1].set_ylabel('每平米房价(万)', fontsize=12) axs[1, 1].grid(True, linestyle='--', alpha=0.4) plt.rcParams['axes.unicode_minus'] = False plt.tight_layout() plt.show()