在python中使用seaborn绘制两个变量的kdeplots

时间:2017-07-11 15:23:06

标签: python seaborn

我使用以下代码为变量绘制两个kdeplots:

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)

但我收到的错误是:

ValueError:观察数量必须大于变量数量。

我不明白为什么会抛出这个错误以及如何绘制这些错误。有人可以帮我解决这个问题。 意图是得到类似的东西: enter image description here

1 个答案:

答案 0 :(得分:3)

您似乎想要绘制两个不同数量的kde图。

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