df.hist()与df.plot.hist()?

时间:2019-07-12 13:35:29

标签: python pandas matplotlib

很抱歉,我的问题似乎很基本,但我找不到直接的答案。当前正在学习有关熊猫可视化的知识,并且不了解df.hist()df.plot.hist()之间的区别(分别参见herehere)。有人可以启发我吗?

1 个答案:

答案 0 :(得分:2)

他们做不同的事情,df.hist()将为每个Series生成一个单独的图,而df.plot.hist()将生成一个堆叠的单个图:

df = pd.DataFrame({
...     'length': [1.5, 0.5, 1.2, 0.9, 3],
...     'width': [0.7, 0.2, 0.15, 0.2, 1.1]
...     }, index= ['pig', 'rabbit', 'duck', 'chicken', 'horse'])
df.hist(bins=3)

产生:

enter image description here

df.plot.hist(bins=3)产生:

enter image description here

因此取决于您想要的东西,它们是针对不同用途的便捷功能。