matplotlib.figure.SubFigure.add_gridspec#

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

用于创建一个以该图形为父级的 GridSpec 的低级 API。

这是一个低级API,允许你创建一个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])