4

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?

3 Answers3

3

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)

mwaskom
  • 46,693
  • 16
  • 125
  • 127
3

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)
cwa
  • 131
  • 2
0

You may upgrade your packages, but it may not be compatible with other libraries such as TensorFlow, so, you may have to downgrade the package.

Ata Tekeli
  • 11
  • 1
  • 6
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 30 '23 at 15:16