获取两个不同变量的单个合并直方图但需要两个不同的图

Getting a single merged histogram for two different variable but want two different plot

Python 绘制直方图的代码

 seaborn.distplot(sub2["S2AQ16A"].dropna(), kde=False);
plt.xlabel('Age')
plt.title('Age when started drinking')

seaborn.distplot(sub2["SIBNO"].dropna(), kde=False);
plt.xlabel('No. of Siblings')
plt.title('No. of Siblings who are alcoholic')

我希望输出是个人的两个直方图 variables.But 得到一个直方图,其中两个变量合并为一个。这是输出的屏幕截图。

如果我 运行 一个一个地编写用于绘制单个变量直方图的代码,同时留下用于绘制其他变量直方图的代码作为注释,我将得到正确的输出。

您正在同一轴上绘制两个直方图。如果您希望它们分开,请将它们绘制在不同的轴上。这是一种方法。

fig, axes = plt.subplots(2, 1)
seaborn.distplot(sub2["S2AQ16A"].dropna(), kde=False, ax=axes[0]);
axes[0].set_xlabel('Age')
axes[0].set_title('Age when started drinking')

seaborn.distplot(sub2["SIBNO"].dropna(), kde=False, ax=axes[1]);
axes[1].set_xlabel('No. of Siblings')
axes[1].set_title('No. of Siblings who are alcoholic')

plt.tight_layout()