Python 如何显示相邻的两个图?

Python 如何显示相邻的两个图?,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,我无法显示相邻的两个DistPlot,单独打印时两个都可以正常工作 f, (ax1, ax2) = plt.subplots(1,2) sns.distplot(df_reqd_data_0['Total_Hood_Group_Earnings'], ax=ax1) plt.show() sns.distplot(df_reqd_data_0['Total_Partner_Earnings'], ax=ax2 ) plt.show() 您需要在两个distplot命令之后调用plot.sh

我无法显示相邻的两个DistPlot,单独打印时两个都可以正常工作

f, (ax1, ax2) = plt.subplots(1,2)

sns.distplot(df_reqd_data_0['Total_Hood_Group_Earnings'], ax=ax1)
plt.show()

sns.distplot(df_reqd_data_0['Total_Partner_Earnings'], ax=ax2 )
plt.show()

您需要在两个
distplot
命令之后调用
plot.show()
命令一次

删除额外的
plot.show()
,使代码如下所示

f, (ax1, ax2) = plt.subplots(1,2)

sns.distplot(df_reqd_data_0['Total_Hood_Group_Earnings'], ax=ax1)

sns.distplot(df_reqd_data_0['Total_Partner_Earnings'], ax=ax2 )
plt.show()

编辑: 除了额外的
plt.show()
,我不确定这里的
sns
是什么。但为了说明我的观点并回答OP发布的问题:

“如何显示相邻的两个distPlot?”

试试这个代码

import matplotlib.pyplot as plt

x = range(10)
y = range(10)

plt.subplot(2,1,1)
plt.plot(y)

plt.subplot(2,1,2)
plt.plot(x)

plt.show()

您可以看到它工作的原因。

sns
是seaborn模块,通常像导入这样导入-
导入seaborn作为sns
。此处有用于特定绘图操作的文档(如果您感兴趣),请接受以下提供的答案,以表明问题已解决