add.subplot() – How to make grid with two rows with different number of columns

Question:

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?

Asked By: tjsmert44

||

Answers:

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

Answered By: Lucas M. Uriarte
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.