使用子图和GridSpec组合两个子图

有时我们想要在用子图创建的轴布局中组合两个子图。我们可以从轴上获取GridSpec,然后移除覆盖的轴并用新的更大的轴填充间隙。 在这里,我们创建一个布局,最后一列中的底部两个轴组合在一起。

请参阅:使用GridSpec和其他功能自定义图布局

使用子图和GridSpec组合两个子图示例

  1. import matplotlib.pyplot as plt
  2. fig, axs = plt.subplots(ncols=3, nrows=3)
  3. gs = axs[1, 2].get_gridspec()
  4. # remove the underlying axes
  5. for ax in axs[1:, -1]:
  6. ax.remove()
  7. axbig = fig.add_subplot(gs[1:, -1])
  8. axbig.annotate('Big Axes \nGridSpec[1:, -1]', (0.1, 0.5),
  9. xycoords='axes fraction', va='center')
  10. fig.tight_layout()

下载这个示例