首页 > 解决方案 > 将多个 seaborn.catplot 堆叠在一起

问题描述

我有多个使用 Seaborn 的不同 FacetGrid 图(来自无法合并的不同数据框)。

每个地块是

g = sns.catplot(x="type", y=outcome, 
                        hue="team",
                        order=types
                        ,ci=68.2,
                        kind="point",aspect=1.3,
                        data=df_temp)

这将给我 6 个这些图(仅显示两个作为示例) 在此处输入图像描述 在此处输入图像描述

我想将它们堆叠在一起,以便在同一斧头上拥有一个同时具有 HH 和 MH 值的图。要得到这样的东西: 在此处输入图像描述

我尝试fig = plt.figure()在循环外部然后fig.axes.append(g.ax)在循环内部(超过 6 个数据帧)但没有成功(我在 fig.axes 中得到一个空数组)

有没有办法做到这一点?

标签: matplotlibseaborn

解决方案


尝试通过轴axcatplot不接受ax参数。

编辑:根据您自己的建议,pointplot通过轴实例时有效ax

fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111)

g = sns.pointplot(x="type", y=outcome, hue="team", order=types, 
                  ci=68.2,data=df_temp, ax=ax)

推荐阅读