1

This is my dataframe:

       age    income  memberdays
0       55  112000.0        1263
1       75  100000.0        1330
2       68   70000.0         978
3       65   53000.0        1054
4       58   51000.0        1144
   ...       ...         ...
14820   45   54000.0         939
14821   61   72000.0         900
14822   49   73000.0        1433
14823   83   50000.0        1758
14824   62   82000.0        1256

I want to create 3 plots in a single figure like this :

fig, ax =plt.subplots(1,3)
sns.countplot(profile["age"], ax=ax[0])
sns.countplot(profile["income"], ax=ax[1])
sns.countplot(profile["memberdays"], ax=ax[2])
fig.show()

This works, but I want to distribution plot with the displot function.

fig, ax =plt.subplots(1,3)
sns.displot(profile["age"], ax=ax[0])
sns.displot(profile["income"], ax=ax[1])
sns.displot(profile["memberdays"], ax=ax[2])
fig.show()

This will result in an empty grid and three indepent plots. Is this the expected behaviour? If yes, why does this happend and how do I overcome it?

Seaborn: 0.11.0

Data Mastery
  • 1,555
  • 4
  • 18
  • 60
  • 1
    `displot` is a figure level function and doesn't accept the `ax=` parameter. Instead, you can use axes-level functions such as `kdeplot` and `histplot`. See the [official overview page](https://seaborn.pydata.org/tutorial/function_overview.html) – JohanC Dec 29 '20 at 10:55

1 Answers1

3

Displot doesn't accept the ax= parameter, try instead to use histplot as follows:

fig, ax =plt.subplots(1,3,figsize=(20,10))
sns.histplot(profile["age"], ax=ax[0])
sns.histplot(profile["income"], ax=ax[1])
sns.histplot(profile["memberdays"], ax=ax[2])
fig.show()

It gives the following output:

Walid
  • 718
  • 5
  • 13