How do I get the longer plot on top using subplots?

Question:

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!

Asked By: wabash

||

Answers:

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

Answered By: Stef
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.