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

标签 python pandas matplotlib

对不起,如果我的问题看起来很基本,但我找不到直接的答案。目前正在学习 pandas 可视化,但不了解 df.hist()df.plot.hist() 之间的区别(参见 herehere , 分别)。有人能启发我吗?

最佳答案

他们做不同的事情,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

所以这取决于你想要什么,它们是用于不同用途的便利功能。

关于python - df.hist() 与 df.plot.hist()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57008086/

相关文章:

python - 按索引值连接 Pandas 多索引数据帧的行

dataframe - 重新索引数据帧时出现问题 : Reindexing only valid with uniquely valued Index objects

python - 来自多个字符串的 TreeMap ,Python

python - 子类中重写的属性 setter 的特殊性

python - 在 Jupyter Notebook 中消失的 Plotly plotly ?

python - Pandas index.get_loc 给出时间序列数据的 keyerror

python - matplotlib:将图例文本颜色与散点图中的符号匹配

python - 使用 pyplot 创建绘图网格

python - 多重最大标注 matplotlib

python - django queryset.update(**kwargs) 上的原子事务