2

This is a simple question, based on this previously asked subplots question: Matplotlib different size subplots

But how do I get the larger plot on top? I know that in plt.subplots(), it's nrows and ncolumns, but I am having trouble placing the larger plot on top and the 3 smaller ones below:

plt.figure(figsize=(12, 6))

ax1 = plt.subplot(2,1,2)
ax2 = plt.subplot(2,3,1)
ax3 = plt.subplot(2,3,2)
ax4 = plt.subplot(2,3,3)

axes = [ax1, ax2, ax3, ax4]

enter image description here

Hoping to get the the bottom plot above the top 3. Thank you!

wabash
  • 779
  • 5
  • 21

1 Answers1

1

You need to specify a 2 x 3 plot layout and make the first plot span all three columns.

See subplot:

index can also be a two-tuple specifying the (first, last) indices (1-based, and including last) of the subplot, e.g., fig.add_subplot(3, 1, (1, 2)) makes a subplot that spans the upper 2/3 of the figure.

plt.figure(figsize=(12, 6))

ax1 = plt.subplot(2,3,(1,3))
ax2 = plt.subplot(2,3,4)
ax3 = plt.subplot(2,3,5)
ax4 = plt.subplot(2,3,6)

enter image description here

Stef
  • 28,728
  • 2
  • 24
  • 52
  • Thank you so much! is there a way to change the figsize of only the top figure? or change the figsize of individual figures within the subplot? – wabash Aug 30 '22 at 08:27
  • 1
    You probably mean the Axes size (figsize is the size of the complete Figure with the 4 Axes). You can change the horizontal and vertical spacing and margins but for complex layouts you may need nested gridspecs. Maybe it's better to ask a separate question with a sketch of how the result should look like. – Stef Aug 30 '22 at 08:32