我想一起绘制两个平行的箱形图。为此,我在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
只需创建两个图,在这种情况下,轴将是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])
非常感谢..代码正常工作..