'df.hist() vs. df.plot.hist()?

Sorry if my question seems basic, but I couldn't find a straight answer. Currently learning about pandas visualization and didn't understand the difference between df.hist() vs. df.plot.hist() (see here and here, respectively). Can someone enlighten me?



Solution 1:[1]

They do different things, df.hist() will produce a separate plot for each Series whilst df.plot.hist() will produce a stacked single plot:

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)

produces:

enter image description here

Whilst df.plot.hist(bins=3) produces:

enter image description here

So it's down to what you want, they are convenience functions for different uses.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 EdChum