合并子图错误 - 'AxesSubplot' 对象没有属性 'get_gridspec'

855*_*732 4 python plot matplotlib python-2.7 python-3.x

使用 python 2.7x,无法升级,因为我在托管 Windows 系统上。我尝试按照此示例合并子图,但返回以下错误:

“AxesSubplot”对象没有属性“get_gridspec”

我在这里查看了其他示例,但找不到任何适用于我正在使用的构建的示例(Anaconda 2.7、Spyder IDE)示例来自:

https://matplotlib.org/tutorials/intermediate/gridspec.html

fig9 = plt.figure(constrained_layout=False)
gs1 = fig9.add_gridspec(nrows=3, ncols=3, left=0.05, right=0.48,
wspace=0.05)
f9_ax1 = fig9.add_subplot(gs1[:-1, :])
f9_ax2 = fig9.add_subplot(gs1[-1, :-1])
f9_ax3 = fig9.add_subplot(gs1[-1, -1])
gs2 = fig9.add_gridspec(nrows=3, ncols=3, left=0.55, right=0.98,
hspace=0.05)
f9_ax4 = fig9.add_subplot(gs2[:, :-1])
f9_ax5 = fig9.add_subplot(gs2[:-1, -1])
f9_ax6 = fig9.add_subplot(gs2[-1, -1]) 
Run Code Online (Sandbox Code Playgroud)

Dav*_*idG 8

查看matplotlib 3及以上版本中添加的文档。 figure.add_gridspec

对于 Python 3.5 及更高版本,您只需将 matplotlib 更新到最新版本即可运行该示例。但是,matplotlib 3 不适用于 Python 2.7 或 Python 3.4 及更低版本。

因此,您可以使用旧文档中描述的旧方法

import matplotlib.gridspec as gridspec

gs1 = gridspec.GridSpec(3, 3)
gs1.update(left=0.05, right=0.48, wspace=0.05)
ax1 = plt.subplot(gs1[:-1, :])
ax2 = plt.subplot(gs1[-1, :-1])
ax3 = plt.subplot(gs1[-1, -1])
Run Code Online (Sandbox Code Playgroud)