【发布时间】:2017-03-11 08:58:43
【问题描述】:
我开始意识到 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 函数时不接受这些关键字参数。
有什么建议吗?
【问题讨论】:
-
你能发布产生错误的代码吗?即,您如何称呼 plt.如果您没有任何子批次(即使只有一个),则不能调用 subplots_adjust() 方法。
标签: python pandas matplotlib subplot