plt.subplot制作空图

时间:2020-09-14 08:02:07

标签: python matplotlib seaborn subplot

我想输入2个表格以适合1行和2列 所以我设置了子图(1,2)但用空图显示(2,2)形状 (我将Jupyter笔记本与%matplotlib inline一起使用)

我该如何解决?

f,ax=plt.subplots(1,2,figsize=(20,8))

sns.barplot('SibSp','Survived',data=train, ax=ax[0])
ax[0].set_title('SibSp vs Survived')

sns.factorplot('SibSp','Survived',data=train, ax=ax[1])
ax[1].set_title('SibSp vs Survived')

plt.show()

enter image description here

1 个答案:

答案 0 :(得分:0)

在Seaborn中,factorplot函数已重命名为catplot。 但是我认为catplot不接受轴参数(虽然不确定)。

最简单的方法是使用pointplot而不是factorplot

f,ax=plt.subplots(1,2,figsize=(20,8))

sns.barplot('SibSp','Survived',data=train, ax=ax[0])
ax[0].set_title('SibSp vs Survived')

sns.pointplot('SibSp','Survived',data=train, ax=ax[1])
ax[1].set_title('SibSp vs Survived')

plt.show()