使用python绘制子图箱线图

使用python绘制子图箱线图,python,seaborn,boxplot,subplot,graph-visualization,Python,Seaborn,Boxplot,Subplot,Graph Visualization,我想把两个平行的盒子画在一起。为此,我在python中使用了sub plots函数,下面是我用于该过程的代码,但我无法从代码中获得良好的输出,因为它已经绘制了两个空图,如何从输出中删除这些空图?请给出一些想法 f, axes = plt.subplots(2,2,figsize = (14,10)) sns.boxplot(x='Heating QC',y='SalePrice',hue='Central Air', data=df ,ax=axes[0,0]) sns.boxplot(x='

我想把两个平行的盒子画在一起。为此,我在python中使用了sub plots函数,下面是我用于该过程的代码,但我无法从代码中获得良好的输出,因为它已经绘制了两个空图,如何从输出中删除这些空图?请给出一些想法

f, axes = plt.subplots(2,2,figsize = (14,10))
sns.boxplot(x='Heating QC',y='SalePrice',hue='Central Air',  data=df ,ax=axes[0,0])
sns.boxplot(x='Heating',y='SalePrice',hue='Central Air',  data=df ,ax=axes[0,1])
输出

更改后低于输出值

IndexError                                Traceback (most recent call last)
<ipython-input-543-7dfa6ebf0390> in <module>
      1 f, axes = plt.subplots(1,2,figsize = (14,10))
----> 2 sns.boxplot(x='Heating QC',y='SalePrice',hue='Central Air',  data=df ,ax=axes[0,0])
      3 sns.boxplot(x='Heating',y='SalePrice',hue='Central Air',  data=df ,ax=axes[0,1])

IndexError: too many indices for array
索引器错误回溯(最近一次调用)
在里面
1 f,轴=plt.子批次(1,2,图尺寸=(14,10))
---->2 sns.箱线图(x='Heating QC',y='SalePrice',hue='Central Air',data=df,ax=axs[0,0])
3 sns.箱线图(x='Heating',y='SalePrice',hue='Central Air',data=df,ax=axs[0,1])
索引器:数组的索引太多

只需创建两个绘图,在这种情况下,轴将是两个元素的列表,并使用这些绘图

请参阅


plt.子地块(2,2)
创建一个2x2的子地块网格,这就是为什么要显示4个地块。您需要根据需要将其更改为
1,2
2,1
@DavidBuck是的,我更改了plt。子图(1,2),然后没有任何输出,只给出错误消息和空两个图。我在问题部分添加了输出和错误信息。您的
ax
现在只需要更改为
轴[0]
轴[1]
,因为您只有一个一维子批次数组。这里介绍:@DavidBuck现在代码正常工作,感谢您的支持。
f, axes = plt.subplots(2, figsize = (14,10))
sns.boxplot(x='Heating QC',y='SalePrice',hue='Central Air',  data=df, ax=axes[0])
sns.boxplot(x='Heating',y='SalePrice',hue='Central Air',  data=df, ax=axes[1])