首页 > 解决方案 > 如何在python中堆叠seaborn pairgrids

问题描述

我正在制作一个将多个因变量与一个自变量进行比较的pairgrid。我有情节,这正是我想要的方式,除了一件事:我不希望情节排在一条很长的线上。

这是我的代码:

g = sns.PairGrid(df, y_vars=["W%"], x_vars=["PPG", "FG%", "3FG%", "FT%", 'APG', 'TOPG', 'RPG'], height=4)
g.map(sns.regplot, color=".3")
plt.ylim(0, 1)

这就是输出。我真的很想以某种方式堆叠它们,第二行也包含 y 轴和刻度。我显然可以用不同的变量运行另一个pairplot,但我希望它们都在同一个轴上。我不在乎它们是如何堆叠的,2x2x2x1、3x3x2、4x3,任何东西都可以。我只是想弄清楚该怎么做。我打算制作一个子图,但 sns.PairGrid() 没有 ax 参数。谢谢!

编辑:我也想知道如何使整个 pairgrid 更大。 在此处输入图像描述

标签: pythonpandasmatplotlibdata-visualizationseaborn

解决方案


使用col_wrapheight参数来sns.FacetGrid

来自 seaborn 教程https://seaborn.pydata.org/tutorial/axis_grids.html

attend = sns.load_dataset("attention").query("subject <= 12")
g = sns.FacetGrid(attend, col="subject", col_wrap=4, height=2, ylim=(0, 10))
g.map(sns.pointplot, "solutions", "score", order=[1, 2, 3], color=".3", ci=None);

推荐阅读