用熊猫调整子图布局

Fou*_*ier 5 python matplotlib pandas subplot

我才明白,matplotlibtight_layout()不能被应用到所产生的地块大熊猫

这是我正在运行的代码:

            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()
Run Code Online (Sandbox Code Playgroud)

我最终遇到以下错误:

AttributeError: 'NoneType' object has no attribute 'is_bbox'
Run Code Online (Sandbox Code Playgroud)

我也相信,这与github上发布的类似问题有关: DataFrame.hist()与matplotlib.pyplot.tight_layout()不相处#9351

因此,我正在寻找基于的解决方法subplots_adjust(*args, **kwargs)。最重要的是,我试图调整hspace参数。但是,调用pandasplot函数时不接受这些关键字参数。

有什么建议么?

piR*_*red 7

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()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


tight_layout()

df.T.plot(kind='bar', subplots=True, width=0.7, legend=False, 
                             layout=(3, 2), sharex=True, sharey=True)
plt.tight_layout()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

  • 好的,如果您想结束这个问题,请继续。抱歉,我发现了问题。我有一个图形布局,其中包含的子图多于用于绘图的子图,并且 pandas 会自动删除它们。当使用ight_layout() 时,我收到上述错误。然而,当仅使用完全适合绘图数量的布局矩阵时,它会起作用! (2认同)