014_散点图_直方图

'''
散点图:
    1 下图房屋面积(sqft_basement)与价格关系(price)
    
直方图:
    1 下图房子集中在什么价位
    2 下图面积集中在什么面积
    
密度图:
    1 下图房子多大概率70w
'''


import pandas as pd
import matplotlib.pyplot as plt


if __name__ == '__main__':
    # 显示设置 - 显示所有列
    pd.options.display.max_columns = 777

    homes = pd.read_excel("C:/Users/123/Desktop/pandas/014_散点图_直方图/home_data.xlsx")
    print(homes.columns)
    print(homes.head())

    # 散点图
    homes.plot.scatter(x = "price", y = "sqft_living")
    plt.show()

    homes.plot.scatter(x = "sqft_living", y = "price")
    plt.show()


    # 直方图 - 面积
    homes.sqft_living.plot.hist(bins=100)    # bins - 设置分布区间
    plt.xticks(range(0, max(homes.sqft_living), 500), fontsize = 8, rotation=90)
    plt.show()

    # 直方图 - 价格
    homes.price.plot.hist()  # bins - 设置分布区间
    plt.xticks(range(0, max(homes.price), 200000), fontsize=8, rotation=90)
    plt.show()
原文地址:https://www.cnblogs.com/huafan/p/14409607.html