Seaborn: Arrange multiple Facetgrids

谁都会走 提交于 2021-01-29 14:51:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!