python - 使用python绘制子图箱线图
问题描述
我想一起绘制两个平行的箱线图。为此,我在 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])
推荐阅读
- javascript - 通过单击具有数字和字符串值的列的表头来对 React 表进行排序
- ide - 无法在 sts 4 上创建 tc 服务器实例
- javascript - 从现有的javascript中克隆一个新对象
- assembly - 有大会ISA要学吗?如果没有,我应该学哪一个?
- xaml - 添加 PasswordBox 附加属性
- python - 如何打印相邻的字符集合
- matlab - 在 Matlab 中使用 parfor,结构随迭代变化
- file - ... 中构造函数的参数 0 需要类型为 ... 的 bean,但无法找到
- c# - 无法使用c#连接oracle数据库
- asp.net - AES 加密数据的长度