import matplotlib.pyplot as plt import pandas as pd plt.rcParams['font.family']='sans-serif' plt.rcParams['font.sans-serif'] = ['Simhei'] plt.rcParams['axes.unicode_minus'] = False filename = "../task/ershoufang_jinan_utf8_clean.csv" names = ["id","communityName","areaName","total","unitPriceValue", "fwhx","szlc","jzmj","hxjg","tnmj", "jzlx","fwcx","jzjg","zxqk","thbl", "pbdt","cqnx","gpsj","jyqs","scjy", "fwyt","fwnx","cqss","dyxx","fbbj", "aa","bb","cc","dd"] miss_value = ["null","暂无数据"] df = pd.read_csv(filename,header=None, skiprows=[0],names=names,na_values=miss_value) 步骤一:二手房总价与建筑面积散点图 通过散点图查看二手房总价和建筑面积的关系。 参考代码: """二手房总价与建筑面积散点图""" fig = plt.figure(figsize=(12,7)) ax = fig.add_subplot(111) ax.set_title("二手房总价与建筑面积散点图",fontsize=18) df.plot(x="jzmj", y="total", kind="scatter",fontsize=12,ax=ax,alpha=0.4,xticks=[0,50,100,150,200,250,300,400,500,600,700],xlim=[0,800]) ax.set_xlabel("建筑面积(㎡)",fontsize=14) ax.set_ylabel("总价(万元)",fontsize=14) 可以看到总价和建筑面积的相关性较强。 步骤二:二手房单价与建筑面积散点图 通过散点图查看二手房单价和建筑面积的关系。 参照下面的提示补全缺失的代码: # 仿照上一节的语句,绘制二手房单价与建筑面积散点图
时间: 2023-07-22 09:09:16 浏览: 162
10.Pandas、Matplotlib、PCA绘图实用代码补充1
请将代码补充如下:
```python
"""二手房单价与建筑面积散点图"""
fig = plt.figure(figsize=(12,7))
ax = fig.add_subplot(111)
ax.set_title("二手房单价与建筑面积散点图",fontsize=18)
df.plot(x="jzmj", y="unitPriceValue", kind="scatter",fontsize=12,ax=ax,alpha=0.4,xticks=[0,50,100,150,200,250,300,400,500,600,700],xlim=[0,800])
ax.set_xlabel("建筑面积(㎡)",fontsize=14)
ax.set_ylabel("单价(元/平米)",fontsize=14)
```
这样就可以绘制二手房单价与建筑面积的散点图了。
阅读全文