This is clearly a bug with the pandas library. The problem seems to arise when by
is a numeric dtype column -- it probably subsets the DataFrame to the labels in column
and by
and then plots that, which is problematic when by
is numeric.
You can either create non-numeric labels for the column that defines your 'by'
, or if you don't want to change your data, it suffices to re-assign the type to object
just before the plot.
Sample Data
import pandas as pd
import numpy as np
df = pd.DataFrame({'length': np.random.normal(0, 1, 1000),
'width': np.random.normal(0, 1, 1000),
'a': np.random.randint(0, 2, 1000)})
# Problem with a numeric dtype for `by` column
df.hist(column=['length', 'width'], by='a', figsize=(4, 2))

# Works fine when column type is object
(df.assign(a=df['a'].astype('object'))
.hist(column=['length', 'width'], by='a' , figsize=(4, 2)))
