嗨,我正在尝试使用matplotlib创建下面的子图。

我有以下代码,但我似乎不能正确配置绘图使用arguments.Would欣赏这方面的任何帮助。欢迎任何其他绘图工具在python上,可以帮助我以这种方式缝合4个绘图。
非常感谢!
gs1 = fig9.add_gridspec(nrows=8, ncols=8, top=0.6, bottom=0.1,left = 0, right = 0.65,
wspace=0.05, hspace=0.05)
# f9_ax1 = fig9.add_subplot(gs1[:-1, :])
ax2 = fig9.add_subplot(gs1[:1, :1])
ax3 = fig9.add_subplot(gs1[:1, 1:])
gs2 = fig9.add_gridspec(nrows=4, ncols=4, top=1.2, bottom=0.4, left = 0, right = 0.5,
wspace=0.05, hspace=0.05)
ax4 = fig9.add_subplot(gs1[1: , :1])
ax5 = fig9.add_subplot(gs1[1:, 1:])上面的代码提供了以下内容

发布于 2020-09-17 18:09:19
例如,您可以在20 x 20网格中划分图形,这意味着一个单元格组成图形的5% x 5%。将比例35/65 -> 7/13、40/60 -> 8/12和50/50 -> 10/10缩放到此栅格可以提供:
import matplotlib.pyplot as plt
fig = plt.figure(constrained_layout=True)
gs1 = fig.add_gridspec(nrows=20, ncols=20)
ax1 = fig.add_subplot(gs1[0:12, 0:7]) # top left (size: 12x7 - 60x35)
ax2 = fig.add_subplot(gs1[0:12, 7:20]) # top right (size: 12x13 - 60x65)
ax3 = fig.add_subplot(gs1[12:20, 0:10]) # bottom left (size: 8x10 - 40x50)
ax4 = fig.add_subplot(gs1[12:20, 10:20]) # bottom right (size: 8x10 - 40x50)

还要注意constrained_layout关键字,将其设置为True会缩小子图以使所有轴标签可见,这可能会产生稍微更改纵横比的影响。将其设置为False时,可以更好地保留比例。但是,当前受约束的布局是experimental,可能会更改或删除。
另请参阅documentation了解更多信息。
发布于 2020-09-17 18:10:12
创建两个单独的网格等级库,您可以将这两个网格等级库的height_ratios都设置为(6, 4),但随后根据需要为它们提供不同的width_ratios。
例如:
import matplotlib.pyplot as plt
fig = plt.figure()
gs1 = fig.add_gridspec(nrows=2, ncols=2, hspace=0.05, wspace=0.05,
height_ratios=(6, 4), width_ratios=(35, 65))
gs2 = fig.add_gridspec(nrows=2, ncols=2, hspace=0.05, wspace=0.05,
height_ratios=(6, 4), width_ratios=(1, 1))
ax1 = fig.add_subplot(gs1[0, 0])
ax2 = fig.add_subplot(gs1[0, 1])
ax3 = fig.add_subplot(gs2[1, 0])
ax4 = fig.add_subplot(gs2[1, 1])
plt.show()

https://stackoverflow.com/questions/63935528
复制相似问题