如何加入子图窗口?

问题描述 投票:0回答:1

假设3x2子图网格;在上方的2x2上,我试图绘制四个不同的图,但下方的1x2将是一个“联合”窗口,如下所示。有两个想法:(1)绘制为单个图形以启用fig.savefig(); (2)保留宽度和高度,即“联合”图应跨越两个子图窗口(不一定是两个子图的宽度的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()
python matplotlib subplot
1个回答
0
投票

[使用docs example(感谢@JohanC),这可以通过用GridSpec指定的“关节轴”替换感兴趣的轴来实现:

GridSpec

© www.soinside.com 2019 - 2024. All rights reserved.