Home > database >  Matplotlib One plot side with multiple subplot
Matplotlib One plot side with multiple subplot

Time:09-05

I am trying to plot some graphs, I want it to look like that, and do it in python.

I tried many things but it looks way uglier than what I want to achieve, any help would be appreciated

enter image description here

CodePudding user response:

you can use a grid try to follow this pattern

from matplotlib.gridspec import GridSpec

fig = plt.figure(constrained_layout=True)
gs = GridSpec(4, 4, figure=fig)
ax1 = fig.add_subplot(gs[:, :2])
# identical to ax1 = plt.subplot(gs.new_subplotspec((0, 0), colspan=3))
ax2 = fig.add_subplot(gs[:2, 2])
ax3 = fig.add_subplot(gs[:2, 3])
ax4 = fig.add_subplot(gs[2:, 2])
ax5 = fig.add_subplot(gs[2:, 3])

plt.show()

enter image description here

CodePudding user response:

You can use enter image description here

CodePudding user response:

Perhaps easier than the above (with relatively modern matplotlib):

fig, axs = plt.subplot_mosaic(
    [['A', 'b', 'c'],
     ['A', 'd', 'e']],
    gridspec_kw={'width_ratios':[2, 1, 1]},
    constrained_layout=True
)

Note that when 3.6 gets released, you can just do:

fig, axs = plt.subplot_mosaic(
    [['A', 'b', 'c'],
     ['A', 'd', 'e']],
    width_ratios=[2, 1, 1],
    constrained_layout=True
)
  • Related