使用 python 绘制子图箱线图

Draw subplots boxplot using python

我想把两个平行的箱形图画在一起。为此,我在 python 中使用了子图函数,在我用于该过程的代码下方,但我无法从代码中得到好的结果,因为它已经绘制了另外两个空图,我如何删除这些空图输出的图表?请为此提供想法?

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

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

参考documentation.

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])