Search code examples
pythonseaborndisplot

Seaborn - displot normalize KDEs for two different sample batches


I was wondering if there is a quick way to normalize the KDE curves (such that the integral of each curve is equal to one) for two displayed sample batches (see figure below).

So far I use:

sb.displot(data=proc, x="TPSA", hue="Data", kind="kde", legend=False)

Giving me the following plot:

non-normalized KDE Plot.

Thanks in advance for the help.


Solution

  • When the hue parameter is set, seaborn by default normalises with respect to the area of all kde curves combined. If you'd like to normalise each curve independently (so the area under each curve is 1), you should provide the displot/kdeplot with common_norm=False.

    e.g. in your case

    sb.displot(data=proc, x="TPSA", hue="Data", kind="kde", legend=False, 
               common_norm=False)