0

I have some data that has widely different scales. I want to create a displot showing all the features on graphic. I though facet_kws={'sharex': False} was the relevant parameter, but it doesn't appear to be working, what I am doing wrong?

import numpy as np
import pandas as pd
import seaborn as sns
import random

# Sample Dataframe
df = pd.DataFrame(np.random.randint(0,200,size=(200, 3)), columns=list('ABC'))
D= np.random.randint(0,10,size=(200, 1))
df['D']= D

# reshape dataframe
df2 = df.stack().reset_index(level=1).reset_index(drop=True).\
    rename(columns={'level_1': 'Name', 0: 'Value'})

# plot
g = sns.displot(data=df2, 
                x='Value', col='Name', 
                col_wrap=3, kde=True,
                facet_kws={'sharex': False})
Rebecca James
  • 383
  • 2
  • 12
  • 1
    https://github.com/mwaskom/seaborn/issues/2472#issuecomment-774032043 – mwaskom Aug 25 '22 at 00:30
  • 1
    Change to `'sharey': False` which corrects issue in above example. As you have multiple plots in the first row, the y-axis needs to be not-shared – Redox Aug 25 '22 at 06:30

1 Answers1

2

The author of Seaborn(mwaskom) already answered at the comment on the question, but I'll answer in more detail.

Use the common_bins option as well, like the following. The documentation on that option is on the histplot() section.

g = sns.displot(data=df2, 
                x='Value', col='Name', 
                col_wrap=3, kde=True,
                common_bins=False,
                facet_kws={'sharex': False, 'sharey': False})

Also I suggest to correct your example code like the following, because it raises a ValueError on duplicate labels, for other readers.

df2 = df.stack().reset_index(level=1).reset_index(drop=True).\
    rename(columns={'level_1': 'Name', 0: 'Value'})
relent95
  • 3,703
  • 1
  • 14
  • 17