问题
I have some trouble understanding seaborns FacetGrids. I have 16 cotegorical columns in my data and I want to use countplot to show the distribution over the values. In addition i have one target variable Y which have to classes. Now I want the calculations for the countplot to be class-dependet. So for each of my 16 input variables I want to have to subplots ( for class 0 and class 1). I can achieve this by (not sure if this is the best solution):
for col in df:
g = sbn.FacetGrid(df, col="Y")
g.map(sbn.countplot, col)
But now I want these 16 plots to be in a 4x4 grid. I tried:
fig, axes =plt.subplots(4, 4, figsize=(18, 10))
for col, ax in zip(df, axes.flat):
g = sbn.FacetGrid(df, col="Y")
g.map(sbn.countplot, col, ax=ax)
plt.tight_layout()
plt.show()
But this does not work. I Also tried:
g = sbn.FacetGrid(df, col="Y")
for col in df:
g.map(sbn.countplot, col)
But only the last col is plotted. Can you help me?
Thanks!
来源:https://stackoverflow.com/questions/60602704/seaborn-arrange-multiple-facetgrids