matplotlib.figure.SubFigure.add_gridspec#

SubFigure.add_gridspec(nrows=1, ncols=1, **kwargs)[源]#

创建以当前图形作为父级的 GridSpec 的底层 API。

这是一个底层 API,允许您创建一个 gridspec,然后根据该 gridspec 添加子图。大多数用户不需要这种自由,而应使用更高级的方法 subplotssubplot_mosaic

参数:
nrowsint, 默认值: 1

网格中的行数。

ncolsint, 默认值: 1

网格中的列数。

返回:
GridSpec
其他参数:
**kwargs

关键字参数会传递给 GridSpec

示例

添加跨两行的子图

fig = plt.figure()
gs = fig.add_gridspec(2, 2)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[1, 0])
# spans two rows:
ax3 = fig.add_subplot(gs[:, 1])