-1

trying to plot density with kdeplot. However, I can not get it to work exactly how I would like.

data = customers groupby gender

if I code


customers.hist(by ='gender', column='total_trans_ct', figsize = [10,6]);```

I get a histogram divided for M and F clients in the dataset. However, I want a density plot so I created

sns.kdeplot(data=customers, x="total_trans_ct", hue="attrition_flag", fill=True, common_norm=False, alpha=0.4);

Which gives me the plot that I want. However, I can't figure out how to divide it into F and M. can anyone please hint how to continue?

I tried the follwing and did not work either

plot = sns.PairGrid(customers['gender'],hue="attrition_flag")
plot = plot.map(sns.kdeplot(data=customers, x="total_trans_ct", fill=True, common_norm=False, alpha=0.4))

when using **kwargs returns error, kwargs not defined

pg2006
  • 1
  • The correct way to do this is with `g = sns.displot(kind='kde', data=customers, x='total_trans_ct', col='gender', hue="attrition_flag", height=10, aspect=1, fill=True, common_norm=False, alpha=0.4)` – Trenton McKinney Nov 04 '22 at 00:58
  • Thank you!! I thought I had done something like that but not sure how it didn't work. I fixed it! – pg2006 Nov 04 '22 at 01:16

1 Answers1

-1

I got it! I was really close. If anyone needs a code like this

plot = sns.FacetGrid(customers, col='gender', hue="attrition_flag", height=10, aspect=1) plot = plot.map(sns.kdeplot,"total_trans_ct", fill=True, common_norm=False, alpha=0.4)

pg2006
  • 1