I am trying to plot a histogram using seaborn. When I try to set kde=True this error is returned:
ValueError: Multi-dimensional indexing (e.g. obj[:, None]
) is no longer supported. Convert to a numpy array before indexing instead.
sns.histplot(data=df, x='age', kde=True);
How can I solve this?
I believe that you have an incompatibility between your version of matplotlib and your version of pandas, with seaborn caught in the middle (source: https://github.com/mwaskom/seaborn/issues/3312)
This can also happen in Matplotlib. I have a virtual environment with matplotlib=3.3.0 and pandas=2.0.2.
A workaround is to use the dataframe's values attribute which will return a numpy array, which can then be used in the plotting function:
plt.plot(df['var_name'].values, df['other_var_name'].values)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With