温馨提示:本文翻译自stackoverflow.com,查看原文请点击:seaborn - Draw subplots boxplot using python
boxplot python seaborn subplot graph-visualization

seaborn - 使用python绘制子图箱图

发布于 2020-04-09 23:14:07

我想一起绘制两个平行的箱形图。为此,我在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])

淘汰

p

更改低于输出后

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

在此处输入图片说明

查看更多

提问者
randunu galhena
被浏览
39
sathyz 2020-02-01 17:41

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

请参阅文档

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