matplotlib.figure.Figure.add_gridspec#
- Figure.add_gridspec(nrows=1, ncols=1, **kwargs)[源码]#
用于创建以当前 figure 作为父级的
GridSpec的底层 API。这是一个底层 API,允许您创建一个 gridspec 并随后基于该 gridspec 添加子图。大多数用户不需要这种灵活性,而应该使用更高级的方法
subplots或subplot_mosaic。示例
添加跨两行的子图
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])