如何在 2x2 网格上绘制多个 seaborn catplots? [英] How to plot multiple seaborn catplots on a 2x2 grid?
本文介绍了如何在 2x2 网格上绘制多个 seaborn catplots?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用FacetGrid绘制2x2网格,每个子图都是相同数据的猫图,但只是具有不同的抖动"值.它没有用.
I tried to use the FacetGrid to plot a 2x2-grid with each subplot being a catplot of the same data, but just with different 'jitter' values. It didn't worked.
这是我现在使用的代码:
Here is the code I am using now:
sns.catplot(x="Sex", y="SidestepDist", jitter=False, data=daten_csv)
sns.catplot(x="Sex", y="SidestepDist", jitter=0.2, data=daten_csv)
sns.catplot(x="Sex", y="SidestepDist", jitter=0.5, data=daten_csv)
sns.catplot(x="Sex", y="SidestepDist", jitter=1, data=daten_csv)
但当然我会像这样得到彼此下面的图:
But of course I get the plots below each other like this:
我怎么能有一个主图,所有 4 个子图都放置为 2x2 矩阵(网格)?
How could I have a main plot, with all 4 subplots placed as a 2x2 matrix (grid)?
推荐答案
所以..我在@ImportanceOfBeingErnest的大力帮助下弄清楚了
So.. I figure it out, with the great help of @ImportanceOfBeingErnest
这是执行此操作的方法:
Here is the way to do it:
fig, ax = plt.subplots(2,2, figsize=(12,10))
jitter = [[False, 1], [0.5, 0.2]]
for j in range(len(ax)):
for i in range(len(ax[j])):
ax[j][i].tick_params(labelsize=15)
ax[j][i].set_xlabel('label', fontsize=17, position=(.5,20))
ax[j][i].set_ylabel('label', fontsize=17)
# x as Hindernisabstand hinzufügen
ax[j][i] = sns.stripplot(x="Sex", y="SidestepDist", jitter=jitter[j][i], data=daten_csv, ax=ax[j][i])
fig.suptitle('Categorical Features Overview', position=(.5,1.1), fontsize=20)
fig.tight_layout()
fig.show()
这是它的样子:
这篇关于如何在 2x2 网格上绘制多个 seaborn catplots?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文