如何加入子图windows?

How to join subplot windows?

假设一个 3x2 子图网格;在上面的 2x2 上,我试图制作四个不同的地块,但底部的 1x2 是 "joint" window,如下所示。两个想法:(1)绘制为单个图形以启用fig.savefig(); (2) 保留宽度和高度,即 "joint" 图应跨越两个子图 windows(不一定是两者宽度的 2 倍),并且高度相同。 MATLAB 能够做到这一点,不确定 matplotlib。


目标图片:


图片代码:

import matplotlib.pyplot as plt
import numpy as np

X = np.random.randn(6, 100, 100)
fig, axes = plt.subplots(2, 2, sharex=True, sharey=True, dpi=72)  # 2x2 for demo

for x, ax in zip(X[:4], axes.flat[:4]):
    ax.imshow(x)
plt.subplots_adjust(left=0, right=.6, bottom=0, top=1, wspace=.01, hspace=.01)
plt.show()

plt.imshow(X[-2:].reshape(100, 200))
plt.gcf().set_size_inches(9.15, 5.5)
plt.show()

拍摄 docs example (thanks @JohanC), this can be accomplished by replacing axes of interest with a "joint axis" specified by a GridSpec:

import matplotlib.pyplot as plt
import numpy as np

X = np.random.randn(6, 100, 100)
fig, axes = plt.subplots(3, 2, sharex=True, sharey=True, figsize=(9, 9))

for x, ax in zip(X, axes.flat[:-2]):
    ax.imshow(x)

gs = axes[0, 0].get_gridspec()
for ax in axes[-1, :]:
    ax.remove()
axbig = fig.add_subplot(gs[-1, :])
axbig.imshow(X[-2:].reshape(100, 200))

fig.subplots_adjust(left=0, right=1, bottom=0, top=1, wspace=-.5, hspace=.02)