Home > Software design >  Python Matplotlib add.subplot() - How to make grid with two rows with different number of columns
Python Matplotlib add.subplot() - How to make grid with two rows with different number of columns

Time:09-04

I would like to plot a composite figure over two rows with one entry on the top row and two on the bottom row, with each subplot having the same aspect ratio. How can this be done?

CodePudding user response:

I think you could follow this pattern

from matplotlib.gridspec import GridSpec

# do not forget constrained_layout=True to have some space between axes
fig = plt.figure(constrained_layout=True)
gs = GridSpec(2, 2, figure=fig)
ax1 = fig.add_subplot(gs[0, :])
# identical to ax1 = plt.subplot(gs.new_subplotspec((0, 0), colspan=2))

ax2 = fig.add_subplot(gs[1, 0])
ax3 = fig.add_subplot(gs[1, 1])

plt.show()

enter image description here

  • Related