Overlay kde plot using Seaborn displot

Question:

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

Asked By: jmich738

||

Answers:

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.

Answered By: mosc9575
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.