powderyporridge
powderyporridge

Reputation: 13

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 advance.

Upvotes: 1

Views: 136

Answers (2)

Jody Klymak
Jody Klymak

Reputation: 5913

@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

Upvotes: 1

Marc
Marc

Reputation: 734

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

cols = 5   #number of columns in the grid
s    = 2   #width of top right subplot in #cells
w    = 1   #spacing between subplot columns

fig = 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

Upvotes: 2

Related Questions