我开始意识到matplotlib的tight_layout()不能应用于pandas生成的图.
这是我正在运行的代码:
0 1 2 3 4
A 0.039895 0.960105 NaN NaN NaN
D 0.030418 0.969582 NaN NaN NaN
E 0.037345 0.962655 NaN NaN NaN
F 0.061522 0.938478 NaN NaN NaN
G 0.047163 0.952837 NaN NaN NaN
H 0.026423 0.000000 0.000000 0.973577 NaN
df.T.plot(kind='bar', subplots=True, width=0.7, legend=False,
layout=(2,4), sharex=True, sharey=True)
plt.tight_layout()
我最终得到以下错误:
AttributeError: 'nonetype' object has no attribute 'is_bBox'
我也相信这与github上发布的类似问题有关:
DataFrame.hist() does not get along with matplotlib.pyplot.tight_layout() #9351
因此,我正在寻找基于subplots_adjust(* args,** kwargs)的解决方法.最重要的是,我试图调整hspace参数.但是,调用pandas的plot函数时不接受这些关键字参数.
有什么建议?
解决方法:
tight_layout()肯定适用于熊猫!
没有tight_layout()
df.T.plot(kind='bar', subplots=True, width=0.7, legend=False,
layout=(3, 2), sharex=True, sharey=True)
# plt.tight_layout()
with tight_layout()
df.T.plot(kind='bar', subplots=True, width=0.7, legend=False,
layout=(3, 2), sharex=True, sharey=True)
plt.tight_layout()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。