pythonseaborndisplot

Overlay kde plot using Seaborn displot


I'm trying to recreate a plot that I made with seaborn distplot but using displot, since distplot is being depreciated.
How do I make the displot overlay the two columns?
Here is the original code to create using distplot:

import pandas as pd
import numpy as np
import seaborn as sns
df1 = pd.DataFrame({'num1':np.random.normal(loc=0.0, scale=1.0, size=100),'num2':np.random.normal(loc=0.0, scale=1.0, size=100)})
sns.distplot(df1['num1'],hist=False,color='orange',)
sns.distplot(df1['num2'],hist=False,color='blue')

enter image description here

Here is the code for the plot using displot

sns.displot(data = df1, x = 'num1',color='orange', kind = 'kde')
sns.displot(data = df1, x = 'num2',color='blue', kind = 'kde')

enter image description here


Solution

  • In think your are looking for kdeplot.

    sns.kdeplot(data=df1, palette=['orange', 'blue'])
    

    Without any special layout I get this result for your example.

    simple kde plot

    I set the palette argument to define the colors as you did in your example, but this is optional.