Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not share axes in FacetGrid

I'm attempting to plot the KDE each column in a dataframe df, with the last column being a boolean with which I plot two hues on each graph, through the use of

sns.pairplot(df, hue='last', palette={True: "#FF0000", False: "#0000FF"}, diag_kind='kde')

This gives me nice KDEs for all of the columns. However, I don't really care for comparing each column pairwise; I only really want to see how the KDEs differ based on the value of last. However, no other method is that elegant. The only other option I've seen is using a FacetGrid, but that has the flaw that the axes limits are all the same. I just can't find a nice way to visualize each column and its relation to the last boolean column.

like image 866
Sebastian Mendez Avatar asked Oct 30 '25 00:10

Sebastian Mendez


1 Answers

I just needed to set sharex and sharey in the FacetGrid.__init__ to False:

sns.FacetGrid(data=df.melt(id_vars=['last']), col="variable", hue="last", 
              palette={True: "#FF0000", False: "#0000FF"}, sharex=False, 
              sharey=False, col_wrap=4).map(sns.kdeplot, 'value', shade=True)
like image 74
Sebastian Mendez Avatar answered Nov 01 '25 14:11

Sebastian Mendez