Python 3.x 如何将多个seaborn CountPlot与共享y轴组合

Python 3.x 如何将多个seaborn CountPlot与共享y轴组合,python-3.x,matplotlib,seaborn,Python 3.x,Matplotlib,Seaborn,嗨,我正在尝试合并多个seaborn CountPlot。 因此,我使用以下代码制作第一个绘图(如下所示): 我正在使用以下代码制作第二个绘图(如下所示): 我的问题是-如何组合这两个(或更多)CountPlot,以使“真/假”为图例,并带有一个公共y轴(如下所示)?我在互联网上搜索了很多,但似乎找不到一种方法来结合这种特殊类型的海生countplot,谢谢 所需绘图: 您只需使用熊猫即可轻松完成: df_new = df.apply(pd.value_counts).T ax=df_new

嗨,我正在尝试合并多个seaborn CountPlot。 因此,我使用以下代码制作第一个绘图(如下所示):

我正在使用以下代码制作第二个绘图(如下所示):

我的问题是-如何组合这两个(或更多)CountPlot,以使“真/假”为图例,并带有一个公共y轴(如下所示)?我在互联网上搜索了很多,但似乎找不到一种方法来结合这种特殊类型的海生countplot,谢谢

所需绘图:


您只需使用熊猫即可轻松完成:

df_new = df.apply(pd.value_counts).T
ax=df_new.plot.bar()
ax.set_xticklabels(ax.get_xticklabels(), rotation=90, ha="right")
plt.tight_layout()
plt.show();

ax1=sns.countplot(x="CommsMailSecondary", data=df, palette="Greens_d",
              order=df.CommsMailSecondary.value_counts().iloc[:5].index)
ax1.set_xticklabels(ax.get_xticklabels(), rotation=90, ha="right")
plt.tight_layout()
plt.show()
df_new = df.apply(pd.value_counts).T
ax=df_new.plot.bar()
ax.set_xticklabels(ax.get_xticklabels(), rotation=90, ha="right")
plt.tight_layout()
plt.show();