Shuvayan Das
Shuvayan Das

Reputation: 1048

Draw kdeplots for two variables using seaborn in python

I am using the below code to draw two kdeplots for a variable:

income_df = attrition_df[['Annual Income','Terminated']]
income_left = income_df.loc[income_df['Terminated'] == 1]
income_stayed = income_df.loc[income_df['Terminated'] == 0]
x = np.array(income_left['Annual Income'].values)
y = np.array(income_stayed['Annual Income'].values)
ax = sns.kdeplot(x,y, shade=True)

But I am getting an error as:

ValueError: The number of observations must be larger than the number of variables.

I do not understand why this error is being thrown and how to draw the plots. Can someone please help me regarding this. Intention is to get something like : enter image description here

Upvotes: 1

Views: 3792

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339250

It seems you want to plot two kde plots of different quantities.

ax = sns.kdeplot(x)
sns.kdeplot(y, ax=ax)

Upvotes: 6

Related Questions