%matplotlib inline # only in a Jupyter notebook
import matplotlib.pyplot as plt
housing.hist(bins=50, figsize=(20,15))
plt.show()
%matplotlib inline 会告诉Jupyter设定好matplotlib,以使用Jupyter自己的后端。show的调用不是必要的,因为代码执行后Jupyter会自动展示图像。
bins:这个参数指定bin(箱子)的个数,也就是总共有几条条状图
figsize:20为直方图横向长度大小,15为直方图纵向长度大小
housing 为 'pandas.core.frame.DataFrame' 类型
上述代码部分运行结果:
将上述代码中的:housing.hist(bins=50, figsize=(20,15)) 改为 housing.hist(bins=20, figsize=(20,15))的部分运行结果如下图:
将上述代码中的:housing.hist(bins=50, figsize=(20,15)) 改为 housing.hist(bins=50, figsize=(10,15))的部分运行结果如下图:
将上述代码中的:housing.hist(bins=50, figsize=(20,15)) 改为 housing.hist(bins=50, figsize=(20,5))的部分运行结果如下图: