Skip to content Skip to sidebar Skip to footer

Customising Matplotlib Subplots

I've always found matplotlib subplots confusing, and so I was wondering whether somebody could show how to generate the following arrangement of subplots: Subplot Image Thanks in a

Solution 1:

You can use plt.GridSpec to easily create differently sized subplots.

cols = 5#number of columns in the grids    = 2#width of top right subplot in #cellsw    = 1#spacing between subplot columnsfig = plt.figure()
gs  = plt.GridSpec(2, cols, figure=fig, wspace=w)
ax1 = fig.add_subplot(gs[0, :-s])
ax2 = fig.add_subplot(gs[0, -s:])
ax3 = fig.add_subplot(gs[1, :-s])

enter image description here

Solution 2:

@Marc 's answer is fine, but perhaps easier and more flexible is:

fig, axs = plt.subplots(2, 2, gridspec_kw={'width_ratios':[2, 1]})
# if you really don't want 4 axes:
fig.delaxes(axs[1, 1])

enter image description here

Post a Comment for "Customising Matplotlib Subplots"