Matplotlib 将子图绘制到现有图形

Neo*_*Neo 6 matplotlib subplot

我想知道是否有等效的功能

fig, axarr = plt.subplots(3, 2, sharex='col', sharey='row')
Run Code Online (Sandbox Code Playgroud)

其中仅为现有图形生成轴数组,而不是创建新图形对象。我基本上需要创建一个 matplotlib 窗口,填充它,并在按下按钮时更新它。我想使用该subplots方法,因为它允许共享轴,但它会强制创建一个新的图形对象,这将打开一个新窗口。

我当前的代码如下所示:

fig = plt.figure()

# When button is pressed
fig.clear()
for i in range(6):
    ax = fig.add_subplot(3, 2, i+1)
    ax.plot(x, y)
plt.draw()
Run Code Online (Sandbox Code Playgroud)

我想做类似的事情

fig, axarr = plt.subplots(3, 2, sharex='col', sharey='row')

# When button is pressed
fig.clear()
axarr = fig.subplots(3, 2, sharex='col', sharey='row')
for i in range(3):
    for j in range(2):
        ax = axarr[i][j]
        ax.plot(x, y)
plt.draw()
Run Code Online (Sandbox Code Playgroud)

或者,有没有办法直接使用 matplotlib 窗口?如果这也是一个选项,我可以将新图形对象绘制到现有窗口中。

如果这有什么不同,我正在使用 PySide 后端。谢谢。

tac*_*ell 1

此功能是通过 PR#5146在主分支上实现的,该分支针对的是 mpl 2.1,该版本应该在秋季发布。

如果您现在需要它,请运行主分支或供应商该方法作为函数

axarr = vendored_subplots(fig, ...)
Run Code Online (Sandbox Code Playgroud)