0
  1. The lines intersect at age 10 here and doesn't go lower than the second 'Survived' line for the rest of the plot.
fig = plt.figure(figsize=(20, 6)) 
sns.kdeplot(x='Age', hue='Survived', data=train, shade=True)
plt.xlim(0,train["Age"].max())
plt.show()

enter image description here

  1. The lines intersect around age 17 here, again at age 30, before the final intersection at age 60.
fac = sns.FacetGrid(train,hue = "Survived", aspect = 5)
fac.map(sns.kdeplot,'Age',shade=True)
fac.set(xlim=(0,train["Age"].max()))
fac.add_legend()

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • 1
    Welcome to stackoverflow. It is unclear what data you show us here and what your expecation is. The Question seems to be not about programming, but about discussing your results. Please improve the question. – user_na Jul 23 '22 at 06:42
  • The main difference is that the first plot uses the default `common_norm=True`, i.e. the curves are scaled down depending on the size of each hue group. For some reason, that parameter doesn't get interpreted the same way in the second plot. The values on the y-axis show the scaling. Note that where exactly these curves intersect is only a very rough approximation of something potentially meaningful, and also depends on the bandwidths used for the kde estimation. – JohanC Jul 23 '22 at 12:46
  • The curves don't "tell stories". When you create a visualization, you have to take into account the data and the interpretation you give to them. You always need to be very aware that a lot of uncertainty is involved. For instance, the curves go outside a valid age range, as the kde approximates via gaussian normals. This doesn't mean such a visualization is "useless", but you shouldn't give too much importance to exact values. – JohanC Jul 23 '22 at 12:51
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 23 '22 at 14:50
  • 1
    Also, upgrade to seaborn 0.11.2. It is not recommended to directly use FacetGrid. Use `sns.displot` with `kind='kde'` – Trenton McKinney Jul 23 '22 at 14:56

0 Answers0