正在尝试在特定的子lot2grid之间添加空间,n

2024-09-29 17:15:19 发布

您现在位置:Python中文网/ 问答频道 /正文

以下将创建10个子批次:

ax1 = plt.subplot2grid((4, 8), (0, 0), colspan=4, rowspan=2)
ax2 = plt.subplot2grid((4, 8), (0, 4), colspan=2, rowspan=1)
ax3 = plt.subplot2grid((4, 8), (0, 6), colspan=2, rowspan=1)
ax4 = plt.subplot2grid((4, 8), (1, 4), colspan=2, rowspan=1)
ax9 = plt.subplot2grid((4, 8), (1, 6), colspan=2, rowspan=1)

ax5 = plt.subplot2grid((4, 8), (2, 0), colspan=4, rowspan=2)
ax6 = plt.subplot2grid((4, 8), (2, 4), colspan=2, rowspan=1)
ax7 = plt.subplot2grid((4, 8), (2, 6), colspan=2, rowspan=1)
ax8 = plt.subplot2grid((4, 8), (3, 4), colspan=2, rowspan=1)
ax10 = plt.subplot2grid((4, 8),(3, 6), colspan=2, rowspan=1)

enter image description here

我想在顶部的一组子窗口和底部的一组子窗口之间添加一行空间。我尝试按如下方式添加一行(以前对我有用,但现在由于某些原因现在不行),并将底部的所有子窗口向下移动一行:

^{pr2}$

但是,它为我生成了两个我没有在这两个空行中请求的空子批(总共给我12个子批)。我只想要两组之间的空行或间距。在

enter image description here


Tags: pltrowspan空行ax1colspan个子ax3ax4
1条回答
网友
1楼 · 发布于 2024-09-29 17:15:19

以下是使用gridspec获得所需内容的方法:

from matplotlib import pyplot as plt
from matplotlib import gridspec

gs = gridspec.GridSpec(5,8)

fig = plt.figure()
ax1 = fig.add_subplot(gs[0:2,0:4])
ax2 = fig.add_subplot(gs[0:1,4:6])
ax3 = fig.add_subplot(gs[0:1,6:8])
ax4 = fig.add_subplot(gs[1:2,4:6])
ax5 = fig.add_subplot(gs[1:2,6:8])


ax6 = fig.add_subplot(gs[3:5,0:4])
ax7 = fig.add_subplot(gs[3:4,4:6])
ax8 = fig.add_subplot(gs[3:4,6:8])
ax9 = fig.add_subplot(gs[4:5,4:6])
ax10 = fig.add_subplot(gs[4:5,6:8])

plt.show()

结果如下:

result of above code

相关问题 更多 >

    热门问题