plot each chart on a different scale with Seaborn Distplot

Question:

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})
Asked By: Rebecca James

||

Answers:

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'})
Answered By: relent95
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.