import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
# 创建画布实例
fig = plt.figure(figsize=(8, 8))
# 创建区域规划图实例
spec = gridspec.GridSpec(ncols=3, nrows=3, figure=fig)
# 在指定位置创建对应的坐标系实例
ax1 = fig.add_subplot(spec[0, :])
ax1.set_title('Subplot 1')
ax2 = fig.add_subplot(spec[1, :2])
ax2.set_title('Subplot 2')
ax3 = fig.add_subplot(spec[1, 2])
ax3.set_title('Subplot 3')
ax4 = fig.add_subplot(spec[2, 0],projection='polar')
ax4.set_title('Subplot 4')
ax5 = fig.add_subplot(spec[2, 1:])
ax5.set_title('Subplot 5')
plt.tight_layout() # 调整子图之间的间距和尺寸,使它们更好地适应画布
plt.show()
运行结果如下