0

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

petezurich
  • 9,280
  • 9
  • 43
  • 57
jmich738
  • 1,565
  • 3
  • 24
  • 41
  • If you convert the DataFrame from wide to long format, it should be possible to use `sns.displot` as instructed in the [documentation](https://seaborn.pydata.org/generated/seaborn.displot.html#) – Kosmos Jul 19 '22 at 06:33
  • yeah that could work. – jmich738 Jul 19 '22 at 07:02
  • `ax = sns.kdeplot(data=df1)` is all that's required get a line for all the columns. But you may also want to specify `common_norm` to match `sns.distplot`. `ax = sns.kdeplot(data=df1, common_norm=False)` – Trenton McKinney Jul 20 '22 at 21:36

1 Answers1

5

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.

mosc9575
  • 5,618
  • 2
  • 9
  • 32