Ben Vincent
Ben Vincent

Reputation: 381

Matplotlib: can you change the relative height of rows using subplots

I have a multi-panel plot that looks like this

multi-panel figure

Code:

f = plt.figure(figsize=(8, 6))
plt.subplot(211)
plt.subplot(245)
plt.subplot(246)
plt.subplot(247)
plt.subplot(248)

I want to keep this layout, but to make the top row take up a larger proportion of the figure. How would I go about making the top tow take up 2/3 of the figure height and the bottom row take up 1/3 of the figure height?

Upvotes: 0

Views: 635

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40667

There are several ways to go about it, most of them are detailed in Customizing Figure Layouts Using GridSpec and Other Functions

Here is a demonstration using GridSpec

gs0 = matplotlib.gridspec.GridSpec(2,4, height_ratios=[2,1])
fig = plt.figure()
ax = fig.add_subplot(gs0[0,:])
ax = fig.add_subplot(gs0[1,0])
ax = fig.add_subplot(gs0[1,1])
ax = fig.add_subplot(gs0[1,2])
ax = fig.add_subplot(gs0[1,3])

enter image description here

Upvotes: 3

Related Questions