我想知道是否有一个相当的函数
fig, axarr = plt.subplots(3, 2, sharex='col', sharey='row')
当只为现有的图形生成轴数组时,而不是创建新的图形对象。我基本上需要创建一个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()
我想做类似以下的事情:
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()
另外,有没有一种直接使用matplotlib窗口的方法?如果可能的话,我可以将新的图形对象绘制到现有窗口中。
如果使用PySide后端,则可能会有所不同。谢谢。
fig, axarr = plt.subplots(...)
或手动创建图形并手动添加子图。如果我没记错的话,plt.subplots
实际上是在 pyplot 源代码中为您自动添加每个新轴,即根据您的第一个示例。 - pathorensubplots
方法可以隐藏某些轴标签,并在使用缩放等交互工具时链接某些子图。我不确定如何复制这些行为。 - Neoadd_subplot
时使用关键字参数sharex = ax_???
或sharey
。例如,如果ax1已经创建,则可以使用语句ax2 = fig.add_subplots(2, 1, 2, sharex=ax1)
实现链接。 - pathoren